Brought up on the RECON slack channel, there was a question about the default
ordering of groups in plot.incidence(). It appears that the order of the
columns is not respected.
library("incidence")
library("ggplot2")
g <- sample(LETTERS[1:5], 100, replace = TRUE)
g <- factor(g, levels = LETTERS[5:1])
i <- incidence(rpois(100, 10), groups = g)
i
#> <incidence object>
#> [100 cases from days 3 to 20]
#> [5 groups: A, B, C, D, E]
#>
#> $counts: matrix with 18 rows and 5 columns
#> $n: 100 cases in total
#> $dates: 18 dates marking the left-side of bins
#> $interval: 1 day
#> $timespan: 18 days
#> $cumulative: FALSE
i$counts <- i$counts[, sample(5)]
i
#> <incidence object>
#> [100 cases from days 3 to 20]
#> [5 groups: B, E, A, C, D]
#>
#> $counts: matrix with 18 rows and 5 columns
#> $n: 100 cases in total
#> $dates: 18 dates marking the left-side of bins
#> $interval: 1 day
#> $timespan: 18 days
#> $cumulative: FALSE
plot(i)
It is possible to change the groups to the correct order with the following
ggplot2 incantation, but ideally this should happen automatically.
Note that this also illustrates a problem where factor levels are not
respected when creating the initial grouping table.
Created on 2018-11-14 by the reprex package (v0.2.1)
Brought up on the RECON slack channel, there was a question about the default ordering of groups in
plot.incidence()
. It appears that the order of the columns is not respected.It is possible to change the groups to the correct order with the following ggplot2 incantation, but ideally this should happen automatically.
Note that this also illustrates a problem where factor levels are not respected when creating the initial grouping table. Created on 2018-11-14 by the reprex package (v0.2.1)