因此,我制作了一些箱形图,希望通过在填充颜色代码后面添加40 (40%)和80 (80%)来逐渐降低颜色透明度。
然而,我正在使用stat_boxplot来拥有漂亮的胡须,其中垂直线现在也可以从boplot....how的盒子后面看到,我要隐藏它们吗?
创建示例df (仅供参考,数据与示例镜像不同):
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))代码:
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")结果:

发布于 2021-06-24 18:50:02
这可以通过添加第二个带有白色color和fill的geom_boxplot来实现,以覆盖框内的errorbars部分:
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")

https://stackoverflow.com/questions/68113194
复制相似问题