0

It is hard to fix errorbar to my points

library(ggplot2)
limits <- aes(ymax = newtable$MN + newtable$SE,ymin = newtable$MN - newtable$SE)

p = ggplot(newtable,aes(Year,MN,group=variable,colour=variable))

p1 = p + geom_point(data=newtable,aes(colour=variable)) + 
         geom_errorbar(data=newtable,limits) + facet_wrap(~Region,scales = "free_y")

enter image description here

Sumedh
  • 4,835
  • 2
  • 17
  • 32
Dian
  • 11
  • 1
  • Welcome to SO! It would be helpful if you post the `dput(newtable)`. Check this [link](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for more – Sumedh Jul 27 '16 at 01:03
  • 2
    A couple of things: You don't have to refer the columns with `$` within `aes`. Since you are using the same `data.frame`, you don't have to mention it within each `geom` – Sumedh Jul 27 '16 at 01:05
  • 1
    not only do you "not have to" - you *shouldn't* use `$`, for the specific reason why your code is not working. You're telling it to plot a vector, when what you really want is for the variable to be interpreted within the environment f your data frame. Drop the `$` wherever it appears in your plotting function, and your problem will probably be solved. – Matt74 Jul 27 '16 at 07:01
  • 1
    Some possible duplicates [here](http://stackoverflow.com/questions/32543340/behavior-ggplot2-aes-in-combination-with-facet-grid-when-passing-variable-wi) and [here](http://stackoverflow.com/questions/33745498/facet-wrap-plotting-incorrect-x-axis-co-ordinates?noredirect=1&lq=1) – aosmith Jul 27 '16 at 14:34
  • Thanks @Sumedh,@Matt74, drop the $ and solve my problem. Yeah!!! – Dian Jul 28 '16 at 05:31

0 Answers0