我如何在 ggplot 中对箱线图上的抖动点进行排序?

问题描述 投票:0回答:1

我的数据(https://drive.google.com/file/d/1cdpVNzw63OaJamvA272WefoTyXIVjaU9/view?usp=drive_link)本质上是水母生长的测量,它们按重复处理(3种不同的孵化温度)进行分类和时间(从一开始的周和天)。 我想以箱线图的形式可视化数据。特别是,对于每一周,我都想通过关联点的处理(或反之亦然)来可视化数据,但 geom_jitter 不会对点进行排序

这就是我现在所做的:

b<- sanderia %>%
  ggplot( aes(x=Week, y=Growth, fill=Treat )) +
    geom_boxplot() +
    scale_fill_viridis(discrete = TRUE, alpha=0.6) +
    geom_jitter( aes(color=Rep, fill=Treat), size=0.4, alpha=0.9) +
    theme_ipsum() +
    theme(
      plot.title = element_text(size=11)
    ) +
    ggtitle("A boxplot with jitter") +
    xlab("")


the output graphic I obtained

我尝试将 geom_jitter 的 aes() 放入填充和组中,但似乎没有任何效果...... 我想以某种方式按周对积分进行排序,这样它们就会落入盒子中

r ggplot2 boxplot
1个回答
0
投票

听起来你想根据点的Week

躲避
点,但也想抖动以清楚地了解它们的关联箱线图。为此,请使用
geom_point
,将
Week
作为分组变量,然后使用
position = position_jitterdodge()
:

library(ggplot2)

ggplot(sanderia, aes(x = Treat, y = Growth, fill = factor(Week))) +
  geom_boxplot(outlier.colour = NA) +
  scale_fill_viridis(discrete = TRUE, alpha = 0.6) +
  geom_point(aes(color = Rep, group = factor(Week)), 
             size = 0.8, alpha = 0.5, 
             position = position_jitterdodge(0.25, 0, 0.75)) +
  hrbrthemes::theme_ipsum() +
  theme(plot.title = element_text(size = 11)) +
  labs(x = NULL, fill = 'Week', title = "A boxplot with jitter") 

© www.soinside.com 2019 - 2024. All rights reserved.