Description Usage Arguments Author(s) Examples
View source: R/epicurver_aggr.R
This function draws an epicurve for aggregated data. Draws a bar for each time unit (usually week, month, year, but also dates are possible). Works with data that has been pre-aggregated per time unit, and with a continuous x-axis (e.g. months or weeks as numbers). Allows using facet_grid() for quick and dirty month/week epicurve spanning over several years.
1 2 3 4 |
data |
Your data frame. |
xvar |
Time variable, given without quotes. |
yvar |
A variable with the number of cases for each time unit, given without quotes. |
group |
If applicable, a grouping variable, given without quotes. Defaults to one group. In case of groupings, works up to 7 groups with ECDC qualitative colours. |
col_scale |
Colour scale for the bars, defaults to qualitative colour scale; select one of the following: "qualitative", "green", "blue", "red". |
border |
Bar border colour, defaults to no border (NA). |
xtitle |
x-axis title. |
x_axis_ticks |
Tick marks for x-axis. Use ONLY if x-axis uses dates or months; select one of the following: "days", "2 days", "weeks", "2 weeks", "months", "years". Defaults to "days" with days and to numbers with numeric weeks or months. Selecting "weeks" prints only mondays for x-axis ticks. In case of "months" labelled automatically with abbreviated month names. |
x_axis_limits |
x-axis limits, for dates use character dates as c("2017-01-01", "2017-12-31"), otherwise a numeric vector lenght of two. |
Legend_title |
Legend title. |
Tommi Karki
1 2 3 4 5 6 7 8 9 10 11 12 13 | # Create dummy data
mydat <- data.frame(ID = c(seq(1,24,1)),
Case = c(sample(10:50, 24, replace = FALSE)),
Month = rep(c(seq(1,12,1)),2),
Gender = c(rep("F",12), rep("M", 12)))
# Plot one epicurve without any groupings
epicurver_aggr(data = mydat[1:12,], xvar = Month, yvar = Case,
xtitle = "Month of onset")
# Plot by two level grouping (e.g. Gender), with tick marks as months
epicurver_aggr(data = mydat, xvar = Month, yvar = Case,
xtitle = "Month of onset", group = Gender, x_axis_ticks = "months")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.