拆分小提琴图(ggplot)的纯色图例?

Solid color legend for split violin plot (ggplot)?

我正试图让这个分裂的小提琴情节中的图例颜色是纯色的。我已成功删除此处的行(在此站点上的 post 之后),但我不知道如何继续。

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)))

我使用了这里的拆分小提琴图的代码

提前感谢您的任何建议!

您的 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