In my package, I like to create a mosaic plot. In the interactive session, this works well. However, if I call the function from an fresh R session with devtools::load_all
, the error "Discrete value supplied to continuous scale" is raised.
Here is a minimum working example:
test_ggmosaic <- function(dat) {
dat <- datasets::mtcars
p <- ggplot2::ggplot(data=dat)+
ggmosaic::geom_mosaic(
ggplot2::aes(weight=mpg,x=ggmosaic::product(gear, cyl), fill=mpg)
) +
ggplot2::theme_bw()+
ggplot2::scale_fill_discrete(guide=ggplot2::guide_legend(reverse=TRUE)
)
return(p)
}
Now when this function is defined inside a package, and ggplot2
and ggmosaic
are added to the Imports
field in the DESCRIPTION
file, and I call this function after loading devtools
and (via load_all
) the package the function is in, I get the error
Fehler: Discrete value supplied to continuous scale
When, on the other hand, I first execute
library(ggplot2)
library(ggmosaic)
and then call the function above, the plot appears (and does not make much sense in this example).