79106053

Date: 2024-10-19 22:20:56
Score: 0.5
Natty:
Report link

It is possible to generate error bars automatically with a tool called superb (summary plot with error bars).

First, lets have more than one point per sample using random data

df2 <- data.frame(
  Sample = rep(c("Sample1", "Sample2", "Sample3", "Sample4", "Sample5"),5),
  Weight = rep(c(10.5, NA, 4.9, 7.8, 6.9),5)+rnorm(25)
)

Then load the library and ask for the plot (default will be to show 95% confidence intervals):

library(superb)
superb( Weight ~ Sample, df2)

Mean plot of the 5 samples

You can ask for standard error (SE) rather than the default confidence intervals (CI) and add any additional formatting options, for example:

p <- superb( Weight ~ Sample, df2,
  errorbar = "SE" # or CI for confidence intervals
) + 
scale_y_continuous(expand = c(0,0), limits = c(0, 12)) + 
theme_classic() + 
theme(axis.text.x = element_text(angle = 45, hjust = 1))
p

Mean plot of the 5 samples with standard error and formating

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Denis Cousineau