首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在透明颜色的箱形图后面隐藏错误条形线?

如何在透明颜色的箱形图后面隐藏错误条形线?
EN

Stack Overflow用户
提问于 2021-06-24 17:33:46
回答 1查看 28关注 0票数 0

因此,我制作了一些箱形图,希望通过在填充颜色代码后面添加40 (40%)和80 (80%)来逐渐降低颜色透明度。

然而,我正在使用stat_boxplot来拥有漂亮的胡须,其中垂直线现在也可以从boplot....how的盒子后面看到,我要隐藏它们吗?

创建示例df (仅供参考,数据与示例镜像不同):

代码语言:javascript
复制
df <- data.frame(Sygmoid = c(1, 2, 3, 5, 6, 3, 6, 5, 9, 5, 8, 5, 4, 4, 4 ,5, 6, 6, 4 ,4 ,5),
                 setup = c(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7))

代码:

代码语言:javascript
复制
lines <- c("#ff0166", "#117f80", "#117f80","#117f80", "#40007f", "#40007f","#40007f")

Sygboxplot <- ggplot(df, aes(x = setup, y = Sygmoid, fill = setup)) +
  stat_boxplot(geom="errorbar", position=pd, width=0.2, lwd=0.75, colour = lines) +
  labs(x = "", y = "Distance (mm)") +
  scale_fill_manual(values=c("#FFFFFF", "#FFFFFF", "#117f8040","#117f8080", "#FFFFFF", "#40007f40","#40007f80")) 

Sygboxplot <- Sygboxplot + geom_boxplot(notch=F, lwd=0.75, fatten = 0.6, position=pd, colour = lines) +
  ggtitle("Sigmoid width") +
  stat_compare_means(comparisons = my_comparisonsSyg[4:6], label.y = c(7, 7.5, 8), label = "p.signif", method = "t.test", paired = T) +
  theme_bw(base_rect_size = 0.2) + 
  ylim(0, 8) 

#Graphpad theme
Sygboxplot <- Sygboxplot + theme_prism(base_size = 14) + theme(legend.position = "none")

结果:

EN

回答 1

Stack Overflow用户

发布于 2021-06-24 18:50:02

这可以通过添加第二个带有白色colorfillgeom_boxplot来实现,以覆盖框内的errorbars部分:

代码语言:javascript
复制
library(ggpubr)

lines <- c("#ff0166", "#117f80", "#117f80", "#117f80", "#40007f", "#40007f", "#40007f")

pd <- position_dodge()

Sygboxplot <- ggplot(df, aes(x = setup, y = Sygmoid, fill = factor(setup))) +
  stat_boxplot(aes(color = factor(setup)),
    geom = "errorbar",
    position = pd, width = 0.2, lwd = 0.75,
  ) +
  labs(x = "", y = "Distance (mm)") +
  scale_fill_manual(values = c("#FFFFFF", "#FFFFFF", "#117f8040", "#117f8080", "#FFFFFF", "#40007f40", "#40007f80")) +
  scale_color_manual(values = lines)

Sygboxplot <- Sygboxplot +
  geom_boxplot(aes(group = factor(setup)), notch = F, fatten = NA,
               position = pd, colour = "white", fill = "white", 
               outlier.colour = NA) +
  geom_boxplot(aes(color = factor(setup)),
    notch = F, lwd = 0.75, fatten = 0.6,
    position = pd, colour = lines
  ) +
  ggtitle("Sigmoid width") +
  # stat_compare_means(comparisons = my_comparisonsSyg[4:6], label.y = c(7, 7.5, 8), label = "p.signif", method = "t.test", paired = T) +
  theme_bw(base_rect_size = 0.2) +
  ylim(0, 8)

# Graphpad theme
Sygboxplot +
  # theme_prism(base_size = 14) +
  theme(legend.position = "none")

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68113194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档