psy*_*iko 7 r ggplot2 boxplot errorbar
我的目标是在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"))
Run Code Online (Sandbox Code Playgroud)
结果如下:
显然,我所拥有的和示例之间存在很多差异,但是现在我只专注于从错误栏中删除端点,我指的是由stat_boxplot
函数创建的水平顶部和底部部分.有谁知道我可以获得预期效果的方式?
的width
在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"))
Run Code Online (Sandbox Code Playgroud)