I have figured out how to make a package that contains some color palettes that I frequently use. I modified the code in this blog post to get it to work. The following code is reproducible.
My specific question though is that this only works when I run the functions create_palette()
and create_palette_list()
below. Those functions, as currently structured to make two objects that have to be available for the functions scale_color_mine()
and scale_fill_mine()
to work. So, my question is how do I modify the code in the package wlucolors
so that those objects are made available the moment the package wlucolors
is loaded.
I think this has something to do with making global variables available to some other functions, and maybe assigning something to the global environment, but I'm really not sure.
Thanks for any insights.
remotes::install_github("sjkiss/wlucolors")
library(wlucolors)
library(tidyverse)
create_palette()
create_palette_list()
data("mtcars")
ggplot(mtcars, aes(x = hp, y = mpg, col = cyl)) +
geom_point() +
scale_color_mine(palette = "federal", discrete = F)
df <- data.frame(party = c("lib", "con", "bq", "ndp", "green"),
voteshare = c(12, 15, 15, 16, 18))
ggplot(df, aes(x = party, y = voteshare, fill = party)) +
geom_col() +
scale_fill_mine(palette = "federal", discrete = T)
df <- data.frame(party = c("lib", "con", "bq", "ndp", "green"),
voteshare = c(12, 15, 15, 16, 18))
ggplot(df, aes(x = party, y = voteshare, fill = party)) +
geom_col() +
scale_fill_mine(palette = "federal", discrete = T)