Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to increase error bar width using stat_summary (ggplot2) in R

I’m following this tutorial to plot a stripchart with error bars, but I’m being unable to control bar width.

# Convert the variable dose from a numeric to a factor variable
ToothGrowth$dose <- as.factor(ToothGrowth$dose)

# Plot
ggplot(data = ToothGrowth, aes(x = dose, y = len, color = dose)) +
  geom_jitter(position = position_jitter(0.2), size = 2, alpha = 0.3) +
  stat_summary(fun.data = mean_se, geom = "pointrange", size = 1.2)

When I add the argument width = 2, R returns:

Warning message:
In stat_summary(fun.data = mean_se, geom = "pointrange", size = 1.2, :
  Ignoring unknown parameters: width

How could I control the width of these error bars?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I think you want linewidth = 2 ?

ggplot(data = ToothGrowth, aes(x = dose, y = len, color = dose)) +
  geom_jitter(position = position_jitter(0.2), size = 2, alpha = 0.3) +
  stat_summary(fun.data = mean_se, geom = "pointrange", size = 1.2, linewidth = 2)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading