我有一个主题函数,我想scale_fill_manual(values=x)
在函数内部添加并更新我的所有图,但是如果我在函数内部添加这条线,它就不起作用my_theme
。另外我不知道如何禁止使用reprex
.
library(tidyverse, quietly = TRUE)
# Here I just create my HEX colors from RGB colors.
x <- tibble(r = c(187, 6, 226, 78, 221),
g = c(180, 110, 223, 118, 128),
b = c(135, 159, 204, 109, 71))
x <- modify(x, as.hexmode) %>%
unite(r, g, b, col="hex", sep="") %>%
map_df(~paste0("#", .x)) %>%
pull()
# This is my theme function and I would like to add scale_fill_manual,
# but then it does not work. I have tried different combinations.
my_theme <- function(){
theme_minimal() +
theme(title = element_text(color = "gray25"),
plot.subtitle = element_text(size=12),
plot.title = element_text(size=12),
plot.caption = element_text(color= "gray30"))
}
# But if I just add it in a separate line then it works.
mpg %>%
ggplot() +
geom_bar(aes(x = fct_infreq(class), fill=factor(cyl)), color="black", width = 0.5) +
labs(title= "CK farver") +
my_theme() +
scale_fill_manual(values = x) +
theme(axis.text.x = element_text(angle = -90, hjust = 0))
由reprex 包(v0.2.0)于 2019 年 4 月 16 日创建。