How to add error bars in ggplot2

Hi

This is my first time making a graph using R studio/R/ggplot2 so I apologize if I don't know what I'm talking about.

I'm really at my wits and end am close to giving up.

I just want to add some error bars onto my graph that shows standard deviation but I can't get it to work. The entirety of the script is more or less copied and I don't have a clue what half of it means.

ttest_a <- t.test(x=my_data$Exposed , y=my_data$Shaded, mu = 0,
alternative ="two.sided", conf = 0.95, var.eq = F,paired = F)

my_data <- read.csv("geum_data.csv")
graph <-ggplot(my_data, aes(exposure, seedling.count, fill = exposure)) +
geom_col(width = 0.5) + theme(axis.title.y = element_text(margin = margin(t = 0, r = 10, b = 0, l = 0)))+
geom_text(aes(label= 38), position=position_dodge(width=0.9), vjust=-0.25) +
labs(fill = "Exposure")

graph <- graph + labs(x = "Exposure", y = "Seedling Count avg.")===]
print (graph)
my_data <- data.frame(
stringsAsFactors = FALSE,
exposure = c("Shaded", "Exposed"),
seedling.count = c(38, 307))

ggplot(my_data, aes(exposure, seedling.count, fill = exposure)) +
geom_col(width = 0.5) +
geom_text(aes(label = seedling.count),
position=position_dodge(width=0.9),
vjust=-0.25) +
labs(x = "Exposure",
y = "Seedling Count avg.",
fill = "Exposure") +
scale_fill_manual(values = c("skyblue1", "purple")) +
theme(axis.title.y = element_text(margin = margin(t = 0, r = 10, b = 0, l = 0)))

and no for some reason reprex isnt working

You can use geom_errorbar()

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

Because you are not providing any sort of sample data, so we can't easily reproduce your issue and try to give you a solution.

i told you reprex wont work. it just highlights what it thinks is the error, ive copied it all out i dont know why that isnt good enough