Reputation: 229
I'm trying to add simple error bars with the ggplot function geom_errobar()
, as I found the code on the web.
The function works, but I don't know why it doesen't put the line between points and bars.
In all examples releted to the explanation of the codes that I found online, there are always a line between points and bars and I used the same code!!!
Short dataset
structure(list(Daytime = structure(c(17683, 17684, 17685, 17686,
17687, 17688, 17689, 17690, 17691, 17692, 17693, 17694, 17695,
17696, 17697, 17698, 17699, 17700, 17701, 17702, 17703, 17704,
17705, 17706, 17707, 17708, 17709, 17710, 17711, 17712), class = "Date"),
mz33_flux = c(0.0269902340425532, -0.0186273777777778, -0.0372041666666667,
-0.065895625, -0.0371895833333333, -0.0685152173913043, 0.0733608695652174,
-0.0462857446808511, 0.03306875, -0.0309327083333333, 0.0240914893617021,
0.0355631578947368, NA, NA, NA, NA, NA, NA, 1.32546206896552,
0.039425, -0.00267916666666666, -0.0299131111111111, -0.207063829787234,
0.0057391304347826, -0.0350862790697674, -0.0324617021276596,
-0.0234354838709677, -0.0835595744680851, 0.0966265957446808,
-0.0124054545454545), mz33_err = c(3.90466069268418e-05,
3.94858430704017e-05, 4.24302022766031e-05, 4.46591337717942e-05,
6.21204244886397e-05, 4.10959733730185e-05, 5.64638070309499e-05,
6.44166726780267e-05, 3.82000202086123e-05, 4.15227904947797e-05,
3.8179357878616e-05, 3.09029031996929e-05, NA, NA, NA, NA,
NA, NA, 0.00102801852277132, 3.86575696937507e-05, 2.93166992687375e-05,
3.24126251499621e-05, 5.68095205509716e-05, 7.24229986669278e-05,
5.91711611807517e-05, 7.34947840597977e-05, 6.30692813002305e-05,
5.4382594393826e-05, 9.84397824539971e-05, 3.30427039605518e-05
)), row.names = c(NA, 30L), class = "data.frame")
ggplot script
ggplot(df,aes(x=Daytime))+
geom_line(aes(y=mz33_flux,colour="y"), size = 1)+
geom_errorbar(aes(ymin=mz33_flux-mz33_err, ymax=mz33_flux+mz33_err), width=1,position=position_dodge(0.05),color="green")
I expect to have connection lines between point and errorbars, as I see in the example plot of the function.
Upvotes: 1
Views: 341
Reputation: 9495
I think that everything is working fine, but you've a very small error, so you have not connection between points and errorbars; if you multiply your error by 1000, you'll have what you're searching for (clearly the data are different):
ggplot(df,aes(x=Daytime,y=mz33_flux,colour="y"), size = 1)+
geom_line()+
geom_point() +
geom_errorbar(aes(ymin=mz33_flux-mz33_err*1000, ymax=mz33_flux+mz33_err*1000),
width=1,
position=position_dodge(0.05),
color="green")
Upvotes: 1