I am trying to create a graph that shows the mean, standard deviation and the dots of each value (jitter). However, I was unable to insert the average point and the standard deviations are the same for all categories (and this is incorrect).
My code (example):
# Package
library(ggplot2)
# Dataframe
fruit <- c()
value <- c()
for (i in 0:30) {
list_fruit <- c('Apple','Banana','Pear')
fruit <- append(fruit, sample(list_fruit, 1))
value <- append(value, sample(1:50, 1))
}
df <- data.frame(fruit, value)
# Seed
set.seed(123)
# Plot
ggplot(df, aes(x = fruit, y = value, color = fruit)) +
geom_point() +
geom_jitter(width = 0.1) +
geom_linerange(aes(ymin = mean(value)-sd(value), ymax = mean(value)+sd(value)), col = 'black') +
scale_color_manual(values=c('red','blue','purple'))