我想使用两个不同的参数(颜色和组)生成几个相似的图。我只能使用组来完成此操作,但是使用颜色矢量无法正常工作。它读取四种调色板颜色,而不是每次读取一种。
pacman::p_load(ggplot2, magrittr)
#make sample data
groups <- letters[23:26]
df <- data.frame(x = rnorm(n = 60,mean = 3.5, sd = 3.4),
y = rnorm(n = 60,mean = 3.5, sd = 3.4),
g = c(rep(groups[1],15),rep(groups[2],15),rep(groups[3],15),rep(groups[4],15)))
colors_pal <- c("#264653", "#2a9d8f", "#457b9d", "#e76f51")
plot_reg_line_equation <- function(df, groups, colors_pal) {
ggplot(data = dplyr::filter(.data = df, g==groups), aes(x = x, y = y)) +
geom_smooth(method = "lm", se=FALSE, color="black", formula = y ~ x) +
geom_point(color = colors_pal) +
ggtitle(label = paste0(groups)) +
jtools::theme_apa() +
theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank())
}
lapply(groups, plot_reg_line_equation, df = df, colors_pal = colors_pal) %>% patchwork::wrap_plots()
#> Error: Aesthetics must be either length 1 or the same as the data (15): colour
由reprex软件包(v0.3.0)创建于2020-12-29
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句