How to input my own Standard Error values for a bar graph in ggplot2

I was searching for some help with R as I am a complete novice and this helped with my problem of not knowing how to input my own "complete" data, as opposed to a list of 1s such as in a matrix. The code (reprex?) that I have copied below produces a bar graph with three bars of corresponding values and names.

Though this solved part of my issue I wondered if there may be a way to do something similar putting my own numbers for my standard error over these bars? For example on bar 1 have a standard error ranging from 17-32?

Fundamentally, I am looking to input my own already calculated standard errors as error bars, instead of R wanting to calculate the error bars for itself, so is there a way that I can specify what my error bars should be?

Many thanks

library(ggplot2)
DF <- data.frame(Name = c("LontNameOne", "LongNameTwo", "LongNameThree"),
                 Values = c(25, 37, 18))
ggplot(DF, aes(Name, Values)) + geom_col(fill = "skyblue") +
  geom_text(aes(label = Values, vjust = 1)) +
  theme(axis.text.x = element_text(angle = 90, hjust = 0.5, vjust = 0.5))

Is this the sort of thing you want to do?

library(ggplot2)
DF <- data.frame(Name = c("LontNameOne", "LongNameTwo", "LongNameThree"),
                 Values = c(25, 37, 18),
                 StdErrorLow = c(20, 30, 15),
                 StdErrorHigh = c(30, 44, 21))
ggplot(DF, aes(Name, Values)) + geom_col(fill = "skyblue") +
  geom_errorbar(aes(ymin = StdErrorLow, ymax = StdErrorHigh), width = 0.2) +
  geom_text(aes(label = Values, vjust = 1, hjust = 1)) +
  theme(axis.text.x = element_text(angle = 90, hjust = 0.5, vjust = 0.5))

Created on 2020-05-20 by the reprex package (v0.2.1)

1 Like