1
votes

I wanted to create a visualisation for some data I had collected using ggplot2. Everything works fine except I cannot add error bars for some reasons. The code I used is the following

graph2 <- ggplot(enth_comb, aes(saturated, eocv, color=oil))
graph2 <- graph2 + geom_point()

This worked fine and resulted in the graph I expected. Then I added the following

graph2 <- graph2 + geom_errorbar(aes(ymin = v_lowlim, ymax = v_highlim))

This gives me the error "Error: geom_errorbar requires the following missing aesthetics: ymin, ymax" despite having provided ymin and ymax. I also tried adding an x value and removing 'aes' but it resulted in the same error.

The data is the followingData Frame

I appreciate any help or suggestions.

Edit: Added output of dput(enth_comb)

structure(list(oil = structure(c(4L, 6L, 3L, 5L, 2L, 1L), .Label = c("coconut", 
"palm", "peanut", "rapeseed", "rice", "sunflower"), class = "factor"), 
    saturated = c(8L, 11L, 17L, 25L, 82L, 88L), sonounsaturated = c(64L, 
    20L, 46L, 38L, 7L, 12L), Polyunsaturated = c(28L, 69L, 32L, 
    37L, 11L, 0L), eocv = c(26991L, 26746L, 28817L, 30056L, 20635L, 
    29497L), eocm = c(31204L, 30892L, 32964L, 34436L, 22979L, 
    33233L), eocv_error = c(2073L, 602L, 1932L, 5578L, 2128L, 
    1267L), eocm_error = c(2396L, 695L, 2210L, 6391L, 2369L, 
    1427L), v_highlim = c(29064L, 27348L, 30749L, 35634L, 22763L, 
    30764L), v_lowlim = c(24918L, 26144L, 26885L, 24478L, 18507L, 
    28230L), m_highlim = c(33600L, 31587L, 35174L, 40827L, 25348L, 
    34660L), m_lowlim = c(28808L, 30197L, 30754L, 28045L, 20610L, 
    31806L)), class = "data.frame", row.names = c(NA, -6L))
1
Try graph2 + geom_errorbar(data=enth_comb,aes(ymin = v_lowlim, ymax = v_highlim))Duck
It gives me the same errorben
Try: ggplot(enth_comb, aes(saturated, eocv, color=oil))+ geom_point()+ geom_errorbar(aes(ymin = v_lowlim, ymax = v_highlim))Duck
I have added as a solution, if you like you could accept the answer if this was helpful for you :)Duck
Would you mind adding a piece of your dataset as data instead of a screenshot? Since your dataset is show short you could copy and paste the result of dput(enth_comb) into your question. Just from looking I don't see a reason the code you wrote doesn't work and so it seems worthwhile to test further in case this is a bug.aosmith

1 Answers

1
votes

The full solution would be concatening all elements:

ggplot(enth_comb, aes(saturated, eocv, color=oil))+
   geom_point()+
geom_errorbar(aes(ymin = v_lowlim, ymax = v_highlim))