-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
In specific_plotting_dynamic.R, we can remove code repetition by putting all aes into the parent call (the ggplot()). This way we can remove the aes from the geom_line, geom_points and geom_errorbar, and put them in a more generic function that we would call similarly in all plotting functions:
Example, instead of:
p <- ggplot2::ggplot(
df_data,
ggplot2::aes(x = .data$Date, colour = .data$variable)
) +
ggplot2::geom_line(ggplot2::aes(y = .data$Simulated)) +
ggplot2::facet_wrap(~ .data$group_var, scales = "free") +
ggplot2::labs(shape = "Variable", colour = "Variable")
if ("Observed" %in% colnames(df_data)) {
p <- p + ggplot2::geom_point(
ggplot2::aes(y = .data$Observed, shape = .data$variable),
na.rm = TRUE
)
if ("Obs_SD" %in% colnames(df_data)) {
p <- p +
ggplot2::geom_errorbar(
ggplot2::aes(
ymin = .data$Observed - 2 * .data$Obs_SD,
ymax = .data$Observed + 2 * .data$Obs_SD,
shape = .data$version
),
na.rm = TRUE
)
}
}We would do:
p <- ggplot2::ggplot(
df_data,
ggplot2::aes(x = .data$Date, colour = .data$variable, shape = .data$variable)
) +
ggplot2::geom_line(ggplot2::aes(y = .data$Simulated)) +
ggplot2::facet_wrap(~ .data$group_var, scales = "free") +
ggplot2::labs(shape = "Variable", colour = "Variable")
p <- add_obs(p)With the add_obs function the function above that adds obs and obs_sd.
Metadata
Metadata
Assignees
Labels
No labels