I would like to change the line thickness of the whiskers when using 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.
Thanks @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).
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.
I am getting the same result with these two pieces of code (both without 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:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With