在 ggplot2 中格式化小提琴图

Formatting a violin plot in ggplot2

我正在努力按照我想要的方式格式化这个小提琴情节。

首先,我想知道如何使绘图、均值和误差条的轮廓与每个显示的点的颜色相同,同时删除这些点的黑色轮廓并将它们的形状更改为相同的每个均值使用一个。其次,我想知道如何降低 x 轴上绘图的宽度并对误差线做同样的事情,这样它们就不会覆盖每把小提琴的整个宽度。

这是我目前拥有的代码:

cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
#
Dta_lng %>% 
  ggplot(aes(x= Group, y= `Glucose m+6`, shape=Group)) +
  geom_violin() +
  geom_errorbar(stat = "summary", fun.data = "mean_sdl", 
                fun.args = list(mult = 1),
                position =  position_dodge(width = 0.9)) +
  geom_jitter(aes(fill=Group),width=0.1, alpha=0.6, pch=21, color="black") +
 #Adjusting limits on Y axis to encompass all data and mimic figure 1a
   ylim(0.0,0.6) +
#Adding colours manually. Original figure is not colour blind friendly so colour blind friendly palette will be used.
  scale_fill_manual(values=cbPalette) + 
  theme_classic() +
  # Inserted mean with the corresponding point shapes from original figure. Size versus the other points was increased so the mean is easily identified.
  stat_summary(fun.y=mean, geom="point", shape=c(16,15), size=3)

数据框如下所示:

Dta_lng

Group Glucose m+6
Efficient 0.4770
Efficient 0.3760
Efficient 0.4960
Efficient 0.3250
Efficient 0.0890
Efficient 0.0460
Efficient 0.2130
Efficient 0.0820
Efficient 0.3590

左栏中也列出了低效因素。

您应该始终提供一些最少的数据,以便我们复制您的结果。

对于颜色,相应的参数是 col = 'color',对于点,您应该尝试 fill = 而不是 col = 。在美学方面尝试使用 group = Group 而不是 shape = Group 以便您可以自己指定形状。

不过我不太了解你的第二个问题。