r - 分割小提琴图(ggplot)的纯色图例?
问题描述
我试图让这个分裂小提琴情节中的传说颜色变得坚实。我已成功删除了此处的行(在此站点上的另一篇文章之后),但我不知道如何继续。
ctn_sv <- ggplot(z, aes(x = time, y = ctn_mean, fill = group), position = position_dodge(.9), alpha = .01) +
geom_split_violin(trim = TRUE, alpha = 0.65) +
ggtitle("CTN: FFF vs ZZZ")+
theme_bw() + theme(legend.title = element_blank()) +
scale_fill_brewer(palette = "Dark2") +
stat_summary(fun = mean, fun.min = mean, fun.max = mean,
geom = "crossbar",
width = 0.25,
position = position_dodge(width = .25)) +
guides(fill = guide_legend(override.aes = list(linetype = 0)),
color = guide_legend(override.aes = list(linetype = 0)))
我使用了这里的分割小提琴图的代码Split violin plot with ggplot2
提前感谢您的任何建议!
解决方案
你的 geom="crossbar" 给你这个问题。您可以在 stat_summary 中使用 show.legend=FALSE 来解决此问题。请参见下面的代码和相应的输出:
set.seed(20160229)
z = data.frame(
y=c(rnorm(1000), rnorm(1000, 0.5), rnorm(1000, 1), rnorm(1000, 1.5)),
x=c(rep('a', 2000), rep('b', 2000)),
group=c(rep('i', 1000), rep('j', 2000), rep('i', 1000))
)
ctn_sv <- ggplot(z, aes(x = x, y = y, fill = group), position = position_dodge(.9), alpha = .71) +
geom_split_violin(trim = TRUE, alpha = 0.65) +
ggtitle("CTN: FFF vs ZZZ")+
theme_bw() +
theme(legend.title = element_blank()) +
scale_fill_brewer(palette = "Dark2") +
stat_summary(fun = mean, fun.min = mean, fun.max = mean,
geom = "crossbar",
width = 0.25,
show.legend = FALSE,
position = position_dodge(width = .25))
ctn_sv
推荐阅读
- python - 使用分隔符分隔行和列并将字符串转换为列表并计算文本文件中最后一列的总和而不使用熊猫
- sql - 使用两个日期的 SQL 查询
- angular - Jest 迁移时令牌无效或意外
- wordpress - 如何从订单中删除结帐页面上的缺货产品并显示它们
- android - 如何从 Android 中的微调器中删除 4 和 5 索引
- apache-spark - 在 databricks 运行时 6.4 中找不到 Spark 2.4.5 from_csv 函数
- python - AttributeError:“NoneType”对象没有属性“GetLayer”
- python - 如何加快此 UTC 转换过程?
- java - Java 将 dateTime 转换为给定的格式
- reporting-services - SSRS 通过单击 ID 字段将参数传递到同一页面中的子报表