简体   繁体   English

如何使用stat_boxplot更改晶须的线宽(geom =“errorbar”)

[英]How to change the line thickness of whiskers using stat_boxplot(geom = “errorbar”)

I would like to change the line thickness of the whiskers when using stat_boxplot(geom = "errorbar") : 我想在使用stat_boxplot(geom = "errorbar")时更改胡须的线条粗细:

set.seed(42)
df <- data.frame(cond = factor( rep(c("A","B"), each=500) ), 
  value = c(rnorm(500,mean=1,sd=0.2),rnorm(500, mean=1.5,sd=0.1)))
ggplot(df, aes(x=cond, y=value)) + geom_boxplot(lwd=0.2)
ggplot(df, aes(x=cond, y=value)) + 
      stat_boxplot(geom = "errorbar", 
       stat_params = list(width = 0.5,size = 5.0)) + 
      geom_boxplot(lwd=0.2)

In the second plot lwd=0.2 changes the thickness of the lines in the box, but the whiskers remain the same. 在第二个图中, lwd=0.2改变框中线条的粗细,但是胡须保持不变。

在此输入图像描述 在此输入图像描述

Update 更新

Thanks @eipi10, 谢谢@ eipi10,

ggplot(df, aes(x=cond, y=value)) + stat_boxplot(geom = "errorbar",
    width = 0.5, size=0.2) + geom_boxplot(lwd=0.2)

your solution changes the thickness of the lines of the whiskers but it makes the horizontal line at their end as wide as the box, instead of half (width = 0.5). 你的解决方案会改变晶须线的粗细,但它会使端部的水平线与盒子一样宽,而不是一半(宽度= 0.5)。

But using 但是使用

ggplot(df, aes(x=cond, y=value)) + stat_boxplot(geom ="errorbar",
    stat_params = list(width = 0.5), size=0.2) + geom_boxplot(lwd=0.2)

or 要么

ggplot(df, aes(x=cond, y=value)) + stat_boxplot(geom = "errorbar",
    stat_params = list(width = 0.5, size=0.2)) + geom_boxplot(lwd=0.2)

then the whiskers width is half of the box as intended but their line thickness is the default one that is thicker than the lines of the box. 那么胡须的宽度是盒子的一半,但它们的线条粗细是默认的厚度比盒子的线条宽。

In other words, I cannot simultaneously change the thickness of the lines and the width of the whiskers. 换句话说,我不能同时改变线条的粗细和胡须的宽度。

Update two 更新两个

I am getting the same result with these two pieces of code (both without stat_params) 我用这两段代码得到了相同的结果(都没有stat_params)

ggplot(df, aes(x=cond, y=value)) + stat_boxplot(geom = "errorbar",
    width=0.5, size=5) + geom_boxplot(lwd=0.2)

ggplot(df, aes(x=cond, y=value)) + stat_boxplot(geom = "errorbar",
    width=0.2, size=5) + geom_boxplot(lwd=0.2)

在此输入图像描述 在此输入图像描述

Jose 何塞

If I understand your question, I think this is what you're looking for: 如果我理解你的问题,我认为这就是你要找的:

ggplot(df, aes(x=cond, y=value)) + 
  stat_boxplot(geom = "errorbar", width=0.5, size=5) +
  geom_boxplot(lwd=0.2)

Here's the result with two different width settings: 这是两个不同width设置的结果:

在此输入图像描述

Try 尝试

ggplot(df, aes(x=cond, y=value)) + stat_boxplot(geom = "errorbar", 
stat_params = list(width = 0.5), geom_params = list(size = 2))
+geom_boxplot(size = 2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM