Description Usage Arguments See Also Examples
View source: R/plotTSGrouped.R
This function draws a time series of the values of variable 'Yvar'
with the time variable 'Xvar' on the x-axis.
The categorical variable that specify the group of the observations
for which there will be one time series each.
Expects aggregated data.
1 2 3 4 5 6 7 8 9 10 11 12 | plotTSGrouped(
.data,
xvar = "",
xlabel = "",
yvar = "",
ylabel = "",
group = "",
fill_color = EcdcColors(col_scale = "qual", n = length(unique(.data[[group]]))),
log10_scale = FALSE,
xvar_format = "%Y",
xvar_breaks = "1 year"
)
|
.data |
dataframe containing the variables to plot |
xvar |
character string, name of the time variable (expects date format) to plot on the x-axis in quotes |
xlabel |
character string, label of the x axis |
yvar |
character string, name of the numerical variable to plot on the y-axis in quotes |
ylabel |
character string, label of the y axis |
group |
character string, name of the grouping variable in quotes, e.g. gender. |
fill_color |
character string, hexadecimal colour to use in the graph;
(default to ECDC green |
log10_scale |
boolean, |
xvar_format |
character string, time format to use to plot the x-axis
( |
xvar_breaks |
character string, time unit to use to plot the x-axis between breaks
( |
Internal function: EcdcColors
Required Packages: ggplot2
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 | # --- Create dummy data
mydat <- data.frame(TimeCode = seq(as.Date("2008/1/1"), as.Date("2017/1/1"), "years"),
YValue = sample(1:79/10, 20),
YLabel = rep(c("Acute", "Chronic"), each = 10))
# --- Plot the dummy data
plotTSGrouped(mydat,
xvar = "TimeCode",
xlabel = "Year",
yvar = "YValue",
ylabel = "Rate per 100 000 population",
group = "YLabel",
log10_scale = TRUE,
xvar_format = "%Y",
xvar_breaks = "1 year")
# --- Create dummy data
mydat <- data.frame(TimeCode = rep(seq(as.Date("2008/1/1"), as.Date("2017/1/1"), "years"), 5),
YValue = c(sample(1:50/10, 10),
sample(1:100/10, 10),
sample(1:300/10, 10),
sample(1:400/10, 10),
sample(1:500/10, 10)),
YLabel = rep(c("United Kingdom",
"France",
"Spain",
"Netherlands",
"Belgium"), each = 10))
# --- Plot the dummy data
plotTSGrouped(mydat,
xvar = "TimeCode",
xlabel = "Year",
yvar = "YValue",
ylabel = "Rate per 100 000 population",
group = "YLabel",
log10_scale = FALSE,
xvar_format = "%Y",
xvar_breaks = "1 year")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.