如何在ggplot2中填充小提琴?
样本数据
Ram2 <- structure(list(
G = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),
levels = c("1", "2"), class = "factor"),
T = c(3, 1, 2, 1, 2, 2, 1, 2, 2, 3, 3, 2, 3, 2, 3, 3, 3, 3, 2, 1, 3, 2, 3,
4, 4, 2, 2, 3, 3, 2)), row.names = c(NA, -30L),
class = c("tbl_df", "tbl", "data.frame"))
这是我的剧本
ggplot(Ram2, aes(x = G, y = T,
color = c('WT', 'at5g01950')[2 - (as.numeric(G) %% 2)]))+
geom_violin(alpha = 0.8, adjust=0.05)+
scale_color_manual(values = c(WT = '#3CBEC3', at5g01950 = '#C3413C')) +
geom_boxplot(width = 0.1, color = "black", alpha = 0.2,
position = position_dodge(0.9)) +
theme_minimal() +
theme(plot.background = element_rect(fill = "white") ,
panel.grid.minor = element_blank()) +
labs(color = '')
这是我的输出
我想把小提琴涂上和轮廓一样的颜色。
谢谢你
我使用fill =“color”,但它用相同的颜色填充两个变量。
1条答案
按热度按时间4zcjmb1e1#
我们可以将其添加到全局
aes()
中,以将评估的颜色复制到填充美学中: