-
Notifications
You must be signed in to change notification settings - Fork 1
Description
I'm having trouble using scale_colour_continuous_sg and scale_colour_discrete_sg when not fully loading the sgplot package, e.g.
library(ggplot2)
data = data.frame(x = 1:4, y = 2*(1:4), z_c = 1:4, z_d = letters[1:4])
ggplot(data, aes(x, y, colour = z_d)) +
geom_point() +
sgplot::scale_colour_discrete_sg()
ggplot(data, aes(x, y, colour = z_c)) +
geom_point() +
sgplot::scale_colour_continuous_sg()
scale_colour_discrete_sg returns an error of
Error in get(paste0(palette_type, "_colour_palettes")) : object 'sg_colour_palettes' not found
scale_colour_continuous_sg returns an error of
Error in as.environment("package:sgplot") : no item called "package:sgplot" on the search list
I assume similar issues exist with scale_fill_*_sg.
My understanding is that the scale_colour_discrete_sg function fails because the "get" call in sg_palette just looks in loaded environments and therefore doesn't find sg_colour_palettes because the package isn't loaded.
scale_colour_continuous_sg is slightly different, with the "get" call specifying the environment to be the sgplot package. But seemingly this doesn't work either. (As far as I can tell, this solution helps if designing another package and setting sgplot in the "depends", but it doesn't seem to help when just coding interactively.
One solution (not necessarily the most elegant) would by to replace
palette_list <- get(paste0(palette_type, "_colour_palettes"))
in sg_palette with
if(palette_type == "sg") palette_list = sgplot::sg_colour_palettes
if(palette_type == "af") palette_list = sgplot::af_colour_palettes
And then the "continuous" versions could be reworked like the discrete ones to call on sg_palette.