error in geom_errorbar

Hi everyone, I have an error in make errorbar in a bar graph. Could anyone help me please?

Here is my code:

p <- ggplot(data1, aes(x=disease, y=newsbsn)) +
geom_col(fill= "blue", colour="black") +
geom_errorbar(aes(ymin=NULL, ymax=newsbsn+se), width=.2)

and it showed

Error: Aesthetics must be either length 1 or the same as the data (107): ymax
Run rlang::last_error() to see where the error occurred.
In addition: Warning message:
In newsbsn + see : longer object length is not a multiple of shorter object length

I assume data1$se exists? or se?

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

once the se column is provided into data1, I expect a subsequent error from the NULL ymin param on errorbar

It is se.
I have 5 groups in ‘disease’, and newsbsn is an biomarker concentration.
I have made boxplot with dotplot successfully.
I want to make a bar graph with error bar, but I only want to show the max value.

library(tidyverse)
data1 <- data.frame(
  disease=letters[1:2],
  newsbsn=sample.int(2,2)
  # ,se=sample.int(2,2)
)

(p <- ggplot(data1, aes(x=disease, y=newsbsn)) +
  geom_col(fill= "blue", colour="black") +
  geom_errorbar(aes(ymin=newsbsn, ymax=newsbsn+se), width=.2))
# object se not found

data2 <- data.frame(
  disease=letters[1:2],
  newsbsn=sample.int(2,2),
  se=sample.int(2,2)
)

(p2 <- ggplot(data2, aes(x=disease, y=newsbsn)) +
  geom_col(fill= "blue", colour="black") +
  geom_errorbar(aes(ymin=newsbsn, ymax=newsbsn+se), width=.2))

I mutated a se column in data1,
But the graph is like this.
library("plotrix")
error <-mutate(data1,se=std.error(newsbsn))

p <- ggplot(error, aes(x=disease, y=newsbsn)) +
geom_col(fill= "blue", colour="black") +
geom_errorbar(aes(ymin=newsbsn, ymax=newsbsn+se), width=.2)

p

I would guess that your data isn't summarised, hence the problem