首页 > 解决方案 > 为什么 geom_errorbar 只在我的情节中间给我一些小线条

问题描述

使用 geom_errorbar 时出现问题。我得到的只是中间的小线,而不是整个范围?!

gd <- data_long %>% 
  group_by(ISItime, FIRST_cat) %>% 
  summarise(mean_ISI= mean(ISIscore, na.rm = TRUE), 
            sd_ISI= sd(ISIscore, na.rm = TRUE))
    
    
gd<- gd %>% 
  mutate(ymax = mean_ISI + sd_ISI, ymin = mean_ISI - sd_ISI)
ggplot(gd, aes(x = ISItime, y = mean_ISI, group= FIRST_cat, color= FIRST_cat)) +
  geom_line (alpha= 0.9, size = 2) + theme_bw() +
  geom_line()+
  geom_errorbar( aes(x=ISItime, ymin=mean_ISI-sd_ISI, ymax=mean_ISI+sd_ISI), width=0.6, 
                 colour="orange", alpha=0.9, size=.3, position=position_dodge(.3))+
  ylim(c(2,12))+ labs(x="Month", y="Mean ISI Score") +
  scale_x_discrete(labels=c("Pre-Study ISI","T0","T1","T2","T3",
                            "T4","T5","T6","T7","T8","T9",
                            "T10","T11","T12")) +
  labs(x = "Timepoint")  

在此处输入图像描述

如果有人可以提供帮助,我将不胜感激。我对自己做错了什么以及为什么我没有得到正确的错误栏感到很困惑。谢谢。

标签: rggplot2errorbar

解决方案


推荐阅读