Add Standard Error Bars to Barchart (2 Examples) | Draw Barplot in Base R & ggplot2 | stat_summary()

Published: 04 July 2022
on channel: Statistics Globe
6,750
82

How to create a barplot with standard error (SE) bars in the R programming language. More details: https://statisticsglobe.com/add-stand...
R code of this video:

set.seed(37924) # Create example data frame
data <- data.frame(values = rnorm(100, 2),
group = letters[1:4])

data_summary <- aggregate(values ~ group, data, # Create summary data
function(x) c(mean = mean(x),
se = sd(x) / sqrt(length(x))))
data_summary <- data.frame(group = data_summary[ , 1], data_summary$values)
data_summary # Print summary data

base_r_barplot <- barplot(data_summary$mean ~ group, # Draw and store Base R barplot
data_summary,
ylim = c(0, 2.7))
arrows(x0 = base_r_barplot, # Add error bars
y0 = data_summary$mean + data_summary$se,
y1 = data_summary$mean - data_summary$se,
angle = 90,
code = 3,
length = 0.1)

install.packages("ggplot2") # Install & load ggplot2 package
library("ggplot2")

ggplot(data, aes(values, group, fill = group)) + # ggplot2 barplot with error bars
coord_flip() +
stat_summary(geom = "bar", fun = mean, position = "dodge") +
stat_summary(geom = "errorbar", fun.data = mean_se, position = "dodge")

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – R Programming Group for Discussions & Questions:   / statisticsglobe  
Facebook – Python Programming Group for Discussions & Questions:   / statisticsglobepython  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – R Programming Group for Discussions & Questions:   / 12555223  
LinkedIn – Python Programming Group for Discussions & Questions:   / 12673534  
Twitter:   / joachimschork  

Music by bensound.com


On this page of the site you can watch the video online Add Standard Error Bars to Barchart (2 Examples) | Draw Barplot in Base R & ggplot2 | stat_summary() with a duration of hours minute second in good quality, which was uploaded by the user Statistics Globe 04 July 2022, share the link with friends and acquaintances, this video has already been watched 6,750 times on youtube and it was liked by 82 viewers. Enjoy your viewing!