使用stat_boxplot绘制误差线,一个因素很好,多个因素对我不起作用

时间:2019-02-21 18:46:20

标签: r ggplot2 boxplot

我正在尝试将误差条(带有晶须)添加到ggplot2箱线图中。通过添加:

stat_boxplot(geom ='errorbar', width = 0.2)

对于一个因素图,一切都很好。对于两个因子图,除了默认的箱形图之外,还添加了条形图。这是尝试之前的情节:

Before

这是后一个:

After

有什么主意我可以解决这个问题吗?

这是之前的版本:

p <- ggplot(data = mwl_long, 
            aes(x = mwl_long$Workload, y = mwl_long$value)) +
  geom_boxplot(notch = TRUE, aes(fill = mwl_long$Condition), width = 0.8) + 
  theme_classic() +
  labs(x = "NASA-TLX Components & Mean", y = "Subjective Workload Rating", 
       fill = "Condition") +  
  theme(axis.text.x = element_text(angle=90)) +
  theme(axis.text.x = element_text(face = ifelse(levels(mwl_long$Workload) == "Overall Mean", "bold", "plain"))) + 
  scale_fill_manual(values=c("white","dark grey"))
p

及之后:

p <- ggplot(data = mwl_long, aes(x = mwl_long$Workload, y = mwl_long$value)) +
  stat_boxplot(geom ='errorbar', width = 0.2) +
  geom_boxplot(notch = TRUE, aes(fill = mwl_long$Condition), width = 0.8) + 
  theme_classic() +
  labs(x = "NASA-TLX Components & Mean", y = "Subjective Workload Rating", 
       fill = "Condition") +  
  theme(axis.text.x = element_text(angle=90)) +
  theme(axis.text.x = element_text(face = ifelse(levels(mwl_long$Workload) == "Overall Mean", "bold", "plain"))) + 
  scale_fill_manual(values=c("white","dark grey"))
p

0 个答案:

没有答案