1
votes

Here is a bit of my data:

df <- structure(list(yrmonth = structure(c(1483228800, 1483228800, 
                                     1483228800, 1485907200, 1485907200, 1485907200, 1488326400, 1488326400, 
                                     1488326400, 1491004800, 1491004800, 1491004800), class = c("POSIXct", 
                                                                                                "POSIXt"), tzone = "UTC"), index = structure(c(1L, 3L, 5L, 1L, 
                                                                                                                                               3L, 5L, 1L, 3L, 5L, 1L, 3L, 5L), .Label = c("N-S", "N-S", "E-W", 
                                                                                                                                                                                           "E-W", "OS"), class = "factor"), N = c(2, 2, 1, 2, 2, 1, 2, 2, 
                                                                                                                                                                                                                                  1, 2, 2, 1), GDDLettuce = c(129, 141, 27, 150.5, 209, 87, 247.5, 
                                                                                                                                                                                                                                                              243, 188, 223, 226.5, 170), sd = c(1.4142135623731, 4.24264068711928, 
                                                                                                                                                                                                                                                                                                 NA, 4.94974746830583, 65.0538238691624, NA, 12.0208152801713, 
                                                                                                                                                                                                                                                                                                 8.48528137423857, NA, 5.65685424949238, 0.707106781186548, NA
                                                                                                                                                                                                                                                              ), se = c(1, 3, NA, 3.5, 46, NA, 8.5, 6, NA, 4, 0.5, NA), ci = c(12.7062047361747, 
                                                                                                                                                                                                                                                                                                                               38.1186142085241, NA, 44.4717165766114, 584.485417864036, NA, 
                                                                                                                                                                                                                                                                                                                               108.002740257485, 76.2372284170481, NA, 50.8248189446988, 6.35310236808735, 
                                                                                                                                                                                                                                                                                                                               NA)), .Names = c("yrmonth", "index", "N", "data", "sd", 
                                                                                                                                                                                                                                                                                                                                                "se", "ci"), row.names = 31:42, class = "data.frame")

When error bars are added to the line graph, they don't always stack on the graph the same way the lines do. How do I change the order of the error bars on the graph?

Here is my graphing code:

ggplot(df, aes(x=yrmonth,y=data,colour=index)) + 
  geom_errorbar(aes(ymin=data-se, ymax=data+se), width = 700000, 
                position = position_jitterdodge(jitter.width = 0, jitter.height = 0,
                                                dodge.width = 200000)) +
  geom_line()

In this case, E-W is on top until march when the error bar is below the line. I would like to adjust it so that all the E-W error bars are on top of the N-S line and error bars.

1
I may be missing something, but is there a reason you are jittering the error bars ? - steveb
@steveb I am jittering to make the bars more visible when they overlap one another - phaser
@PKr edited accordingly. - phaser
Sorry, but I don't get what is not working exactly... - Umberto

1 Answers

0
votes

I use the answer field since I want to paste a Picture. If you remove your jitter the error bars seems to be positioned correctly (they are not pleasant to see in my Picture, but the positions are ok). Or maybe I am not getting your Problem?

ggplot(df, aes(x=yrmonth,y=data,colour=index)) + 
  geom_errorbar(aes(ymin=data-se, ymax=data+se), width = 700000) + geom_line()

enter image description here