I need to find for every numeric variable in Iris data set mean and standard deviation by Species and draw that in ggplot2 graph with geom_col and geom_errorbar.
This is what I got so far
library(tidyverse)
data(Iris)
iris %>%
group_by(Species) %>%
summarise_if(is.numeric, list(mean = mean, sd = sd)) -> IrisData
I tried to create a graph but I don't know how to use the geom_errorbar
IrisData %>%
select(Species, ends_with("mean")) %>%
gather(key, val, 2:5) %>%
ggplot(aes(key, val, fill = Species)) +
geom_col()
I found that it should look something like this
geom_errorbar(aes(ymin = mean - sd, ymax = mean + sd), width=0.2)
But I'm not sure how to use it, I added this to the end of code and I get some graph but I'm sure it's not right
geom_errorbar(aes(ymin = val - sd(val), ymax = val + sd(val)), width=0.2, size = 1.2)