我的目标是在 R 中创建箱线图(不一定要使用 ggplot2,但这就是我现在使用的),其风格与我在某处找到的示例相似(减去文本):
这是我到目前为止的代码:
dat <- read.table(file = "https://www.dropbox.com/s/b59b03rc8erea5d/dat.txt?dl=1", header = TRUE, sep = " ")
library(ggplot2)
p <- ggplot(dat, aes(x = Subscale, y = Score, fill = Class))
p + stat_boxplot(geom = "errorbar", width = 1.2, size = 2.5, color = "#0077B3") +
geom_boxplot(outlier.shape = NA, coef = 0, position = position_dodge(.9)) +
scale_fill_manual(values = c("#66CCFF", "#E6E6E6")) +
theme(panel.background = element_rect(fill = "white", color = "white"))
结果是:
显然,我所拥有的和示例显示的之间有很多差异,但现在我只专注于从误差条中删除端点,我的意思是由stat_boxplot
功能。有谁知道我可以达到预期效果的方法吗?
The width
in the errorbar
geom 控制水平端条的宽度,因此将其设置为 0 以删除端条。你错过了躲避stat_boxplot
层,因此您可以添加它以正确避开误差线。
ggplot(dat, aes(x = Subscale, y = Score, fill = Class)) +
stat_boxplot(geom = "errorbar", width = 0, size = 2.5,
color = "#0077B3", position = position_dodge(.9)) +
geom_boxplot(outlier.shape = NA, coef = 0, position = position_dodge(.9)) +
scale_fill_manual(values = c("#66CCFF", "#E6E6E6")) +
theme(panel.background = element_rect(fill = "white", color = "white"))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)