epicurver: Epicurver

Description Usage Arguments Author(s) Examples

View source: R/epicurver.R

Description

This function draws an epicurve, either one square per each case or bars per time unit. Requires case-based data, currently requires either a column with 1's or Yes's for cases. Draws by dates, or by continuous x-scale (weeks, months, years). Note that accepts also a line list with 1/0 or Yes/No for case/non-case. Use squares = FALSE if large number of cases or long time interval.

Usage

1
2
3
4
epicurver(data, xvar, yvar, group = NULL, squares = TRUE, ymax = NULL,
  xtitle = "Time", legend_title = group, col_scale = "qualitative",
  border = "white", x_axis_ticks = c("days", "2 days", "weeks", "2 weeks",
  "months", "years"), x_axis_limits = NULL)

Arguments

data

Your data frame/line list.

xvar

Variable with the date, week, month or year of onset (requires long format data), given without quotes.

yvar

Variable with cases/non-cases as 1/0 or Yes/No (also allows data with only 1's), given without quotes.

group

If applicable, a grouping variable, given without quotes. Defaults to one group (cases), in which leaves the legend unprinted. In case of groupings, works up to 7 groups with ECDC colours.

squares

Whether to draw one square for each case or only one bar per time unit. Defaults to one square per case, use "FALSE" in case of large number of cases or long time intervals.

ymax

y-axis upper limit, defaults to max number of cases per time unit. Tick marks are always pretty.

xtitle

x-axis title.

legend_title

Legend title

col_scale

Colour scale for the squares/bars, defaults to qualitative colour scale; select one of the following: "qualitative", "green", "blue", "red".

border

Square/bar border colour, defaults to "white". "NA" removes the borders.

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.

Author(s)

Tommi Karki

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Create dummy data
mydat <- data.frame(ID = c(seq(1,10,1)),
Gender = c(rep(c("F", "M"),5)),
AgeGroup = c(rep(c("0-18", "18-65", "65+"),3), "65+"),
Case = c(1,1,1,0,0,1,1,1,1,1),
Cases_char = c(rep("Yes",3), "No", "No", rep("Yes", 5)),
DateOfOnset = as.Date(c("2017-06-11", "2017-06-11", 
                       "2017-06-11", NA, NA, "2017-06-10", 
                       "2017-06-14", "2017-06-14",
                       "2017-06-19", "2017-06-19")),
Month = c(sample(c(3:6),5, replace = TRUE), sample(c(1:12),5)),
Week = c(sample(c(10:12),5, replace = TRUE), sample(c(1:53),5)))

# Plot
epicurver(data = mydat, xvar = DateOfOnset, yvar = Case, ymax = 5)

# Plot by two level grouping (e.g. Gender)
epicurver(mydat, xvar = DateOfOnset, yvar = Case, ymax=5, group = Gender)

# Plot by multilevel grouping (e.g AgeGroup)
epicurver(mydat, xvar = DateOfOnset, yvar = Case, ymax=5, group = AgeGroup,
xtitle = "Date of onset")

# Plot by months using x-axis options
epicurver(mydat, xvar = Month, yvar = Case, ymax = 5, x_axis_ticks = "months", 
xtitle = "Month of onset")

# Plot with character Yes/No cases variable
epicurver(mydat, xvar = Month, yvar = Cases_char, ymax = 5, x_axis_ticks = "months", 
xtitle = "Date of onset of disease x")

# Create bigger dummy data
biggerdat <- data.frame(ID = c(seq(1,1000,1)),
Case = 1, Month=round(rnorm(1000, mean=6, sd=1.5)),
Gender = rep(c("F", "M"),500))

# Plot by months using squares = FALSE and border = NA
epicurver(biggerdat, xvar = Month, yvar = Case, squares = FALSE, 
xtitle = "Month of onset", x_axis_ticks = "months", border = NA)

Plot by months using squares = FALSE and by grouping
epicurver(biggerdat, xvar = Month, yvar = Case,  group = Gender,
squares = FALSE, xtitle = "Month of onset", x_axis_ticks = "months")

TommiKarki/EpiMethods documentation built on Dec. 6, 2019, 4:48 a.m.