reconhub / incidence

☣:chart_with_upwards_trend::chart_with_downwards_trend:☣ Compute and visualise incidence
https://reconhub.github.io/incidence
Other
58 stars 13 forks source link

Add plot argument show_cases to overlay squares #72

Closed zkamvar closed 5 years ago

zkamvar commented 5 years ago

This was a request from the Bulgaria workshop and in general from EPIET folks. @jakobschumacher had contributed an example of how to do this using horizontal lines in the vignette. However, adding this as a single option is best to avoid frustrated epis (as @aspina7 mentioned). Here's what it looks like in practice:

library(incidence)
library(outbreaks) 
require(ggplot2)
#> Loading required package: ggplot2

onset <- ebola_sim$linelist$date_of_onset
sex <- ebola_sim$linelist$gender
inc.week.gender <- incidence(onset, interval = 7, groups = sex)

## show individual cases at the beginning of the epidemic
inc.week.8 <- subset(inc.week.gender, to = "2014-06-01")

plot(inc.week.8, show_cases = TRUE, border = "black")


## customize plot with ggplot2
plot(inc.week.8, show_cases = TRUE, border = "black") +
  theme_classic(base_size = 16) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))


## a message is issued if the user chooses stack = FALSE
plot(inc.week.8, show_cases = TRUE, stack = FALSE)
#> the argument `show_cases` requires the argument `stack = TRUE`

Created on 2018-10-31 by the reprex package (v0.2.1)

zkamvar commented 5 years ago

Since the check passed, I'm going to merge this feature into the master branch.

aspina7 commented 5 years ago

happy to see @jakobschumacher working on this! (servus!) Think the episquares addition would make a lot of epis quite happy, but the horizontal lines i dont think is the cleanest solution for this, can get quite messy!

zkamvar commented 5 years ago

but the horizontal lines i dont think is the cleanest solution for this, can get quite messy!

Agreed. That's why in this PR, I've swapped out horizontal lines for an extra grid of empty cells overlaying the bars. It makes it so you can add obnoxious colors to the chart:

library(incidence)
library(outbreaks) 
require(ggplot2)
#> Loading required package: ggplot2

onset <- ebola_sim$linelist$date_of_onset
sex <- ebola_sim$linelist$gender
inc.week.gender <- incidence(onset, interval = 7, groups = sex)

## show individual cases at the beginning of the epidemic
inc.week.8 <- subset(inc.week.gender, to = "2014-06-01")

plot(inc.week.8, show_cases = TRUE, border = "purple", color = c(f = "grey20", m = "grey80"))

Created on 2018-10-31 by the reprex package (v0.2.1)

aspina7 commented 5 years ago

ah sweet, love it! Obnoxious colours very majestic. Chucking coord_equal() on the end sometimes makes nice boxes making cleaner looking, but depends on number of cases and timeframe