Closed mllstrm closed 1 year ago
Hi @mllstrm.
The vignette is now outdated. It should have been removed from online when the new version of incidence2 was released. I've now removed it. I'll investigate the best way to create that particular plot style and get back to you.
Thanks! I find that plot very usefull! Ha en trevlig dag! (Have I nice day!)
@mllstrm - Is this style of plot mainly utilised when you have <Date>
objects? (i.e. daily data as opposed to weekly/monthly). If so I can probably get something released relatively soon that restores the behaviour.
both, it varies depending on the type of outbreak, usually it is daily data or weekly data
@mllstrm - I'm experimenting with a fix to this in the fix107 branch.
If you're happy to install from GitHub you can try it out via
remotes::install_github("reconverse/incidence2@fix107")
Let me know what you think. It's not identical to the previous version but hopefully close enough?
library(outbreaks)
library(incidence2)
#> Loading required package: grates
dat <- ebola_sim_clean$linelist
i_epiet <- incidence(dat[160:180, ], date_index = "date_of_onset")
plot(i_epiet, show_cases = TRUE, angle = 45, size = 10, n_breaks = 20)
excellent! I'm out of the office today but will try it first thing tomorrow!
Will it be possible to color the boxes based on different characteristics? for example confirmed and suspected cases
Thanks!
Not at the moment but it is something we can work on. Currently, groups automatically facet the output, e.g.
library(outbreaks)
library(incidence2)
# synthetic data
dat <- ebola_sim_clean$linelist
# add suspected/confirmed at random
dat$confirmed = sample(c("suspected", "confirmed"), size = nrow(dat), replace = TRUE)
# build incidence object with the appropriate grouping
i_epiet <- incidence(
dat[160:180, ],
date_index = "date_of_onset",
groups = "confirmed",
date_names_to = "date"
)
# plot - note without `nrow = 2` this would display in 2 columns not rows
plot(i_epiet, show_cases = TRUE, angle = 45, size = 10, n_breaks = 10, nrow = 2)
We designed {incidence2} is to have "reasonable" defaults for plots but to encourage people to fall back to direct use of {ggplot2} for more complicated/custom cases (although we probably want to support this style of filling). Currently the more more manual approach to achieve what you're after is something similar to:
library(dplyr)
library(tidyr)
library(ggplot2)
library(scales)
i_epiet |>
uncount(count) |>
mutate(count = 1) |>
ggplot(aes(x = date, y = count, fill = confirmed)) +
geom_col(colour = "white", alpha = 0.7, width = 1) +
theme_bw() +
coord_equal() +
scale_fill_manual(values = vibrant(2), na.value = "grey") +
scale_x_date(breaks = breaks_pretty(10)) +
theme(axis.text.x = element_text(hjust = 1, angle = 45, size = 10))
I'll raise an issue to reintroduce the plotting vignette as we can capture some of these discussions/approaches within that.
Created on 2023-05-31 with reprex v2.0.2
@mllstrm - Installing from the current master branch
remotes::install_github("reconverse/incidence2")
We should now have
library(outbreaks)
library(incidence2)
#> Loading required package: grates
# synthetic data
dat <- ebola_sim_clean$linelist
# build incidence object and plot
i_epiet <- incidence(
dat[160:180, ],
date_index = "date_of_onset",
date_names_to = "date"
)
plot(i_epiet, show_cases = TRUE, angle = 45, n_breaks = 10)
# add suspected/confirmed at random
dat$evidence = sample(c("suspected", "confirmed"), size = nrow(dat), replace = TRUE)
# build incidence object with the appropriate grouping
i_epiet2 <- incidence(
dat[160:180, ],
date_index = "date_of_onset",
groups = "evidence",
date_names_to = "date"
)
# plot with fill set to evidence
plot(i_epiet2, show_cases = TRUE, angle = 45, n_breaks = 10, fill = "evidence")
# without fill being set we will automatically facet. We set nrow = 2, to force
# the facetting to occur across rows not columns.
plot(i_epiet2, show_cases = TRUE, angle = 45, n_breaks = 10, nrow = 2)
Created on 2023-05-31 with reprex v2.0.2
It works! Thank you so much!
Please place an "x" in all the boxes that apply
Hi!
Since my R version were upgraded from 4.0.0. I have some problem with incidence2.
Take this example:
https://www.reconverse.org/incidence2/articles/customizing_incidence_plots.html#applying-the-style-of-european-programme-for-intervention-epidemiology-training-epiet
It does not display individual cases as rectangles