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

Allow for single group to not be ignored when plotting or creating data frames #85

Closed zkamvar closed 5 years ago

zkamvar commented 5 years ago

Currently, if there is only a single grouping variable, the plotting and conversion are treated as if no groups exist. This is erroneous because if the user specifies a group in the incidence call, it should be respected.

This PR will fix #84 and this behavior in three ways:

  1. as.data.frame() will return the column name instead of counts and will add a groups column when long = TRUE.
  2. plot() will respect single groups
  3. plot() will inform users if there were colors not used
library("incidence")
library("ggplot2")
i <- incidence(rpois(100, 5), groups = rep("look!", 100))
my_colors <- c("at" = "blue", "this" = "pink", "look!" = "purple")
plot(i, color = my_colors)
#> 2 colors were not used: "at" = "blue", "this" = "pink"

# From issue #84
plot(i) + scale_fill_manual(name = "Hey!", values = my_colors)
#> Scale for 'fill' is already present. Adding another scale for 'fill',
#> which will replace the existing scale.

Created on 2018-12-07 by the reprex package (v0.2.1)


I still need to write tests for this, but the basic machinery is there. Thanks again to @pbkeating for pointing this out!

zkamvar commented 5 years ago

Appveyor can go die in a fire. It's currently failing because of unrelated issues. I will merge this.