I am plotting error bars on my data using output from the summarySE() function in the Rmisc package. I would like to change the width of the horizontal lines on each error bar. For some reason, width is not working properly.
I have looked at solutions and NONE of them worked:
Width of error bars in ggplot2
ggplot2 position_dodge affects error bar width
Nothing has worked. Here is a snip it of my data:
df <- structure(list(yrmonth = structure(c(1456790400, 1456790400,
1456790400, 1459468800, 1459468800, 1459468800, 1462060800, 1462060800,
1462060800, 1464739200, 1464739200, 1464739200), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), index = structure(c(1L, 4L, 5L, 1L,
4L, 5L, 1L, 4L, 5L, 1L, 4L, 5L), .Label = c("N-S", "N-S", "E-W",
"E-W", "OS"), class = "factor"), N = c(2, 1, 1, 2, 1, 1, 2, 1,
1, 2, 1, 1), GDDTomatoes = c(151, 136, 61, 221.5, 211, 151, 273,
253, 207, 376, 386, 362), sd = c(7.07106781186548, NA, NA, 3.53553390593274,
NA, NA, 0, NA, NA, 5.65685424949238, NA, NA), se = c(5, NA, NA,
2.5, NA, NA, 0, NA, NA, 4, NA, NA), ci = c(63.5310236808735,
NA, NA, 31.7655118404367, NA, NA, 0, NA, NA, 50.8248189446988,
NA, NA)), .Names = c("yrmonth", "index", "N", "value",
"sd", "se", "ci"), row.names = c(NA, 12L), class = "data.frame")
Here is one of my ggplot attempts that didn't work. When I use the width parameter, no matter what number I put in width the horizontal lines disappear altogether. I would just like to shorten them a bit.
ggplot(df, aes(x=yrmonth,y=value,colour=factor(index))) +
geom_errorbar(aes(ymin=value-se, ymax=value+se), width=0.5) +
geom_line()

geom_errorbarwidth adjust relative width based on the number of levels of factors of x. In your data, the x value is a continuous gradient. Change it to a factor and you will be able to manipulate the width forgeom_errorbar. Alternatively, go withgeom_ribbon. - Adam Quekyrmonthand then look at the numeric value of thewidthparameter you're trying. You should probably try something along the lines ofwidth = 1e6to get them to show up at that scale. - Brianyrmonthis encoded as numbers of seconds since 1970. That means the space between two values on the x-axis is a few million seconds. If your errorbar was only half a second wide, it would be invisible. - Brian