【发布时间】:2023-03-08 03:08:01
【问题描述】:
我想出了如何制作一个包含一些我经常使用的调色板的包。我修改了this 博客文章中的代码以使其正常工作。以下代码可重现。
我的具体问题是,这仅在我运行下面的函数 create_palette() 和 create_palette_list() 时才有效。这些函数,目前的结构是为了使两个对象必须可用于函数scale_color_mine() 和scale_fill_mine() 才能工作。所以,我的问题是如何修改包wlucolors 中的代码,以便在加载包wlucolors 的那一刻使这些对象可用。
我认为这与使全局变量可用于其他一些函数有关,并且可能将某些内容分配给全局环境,但我真的不确定。
感谢您提供任何见解。
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)
【问题讨论】:
-
你在找
.onLoadhere吗?