With this data x <- c(0,0,1,1,2,2) y <- c(5,6,4,3,2,6) lwr <- y-1 upr <- y+1 xlab <- c("Low","Low","Med","Med","High","High") mydata <- data.frame(x,xlab,y,lwr,upr) I would like to make a dot plot and use lwr and upr as error bars. Above 0=Low. I would like there to be some space between the 5 and the 6 corresponding to Low so I tried jittering: p <- ggplot(mydata, aes(x=x, y=y)) p+geom_point() p + geom_jitter(position=position_jitter(xjitter=2)) But I obtained this error: Error in get("new", env = PositionJitter, inherits = TRUE)(PositionJitter, : unused argument(s) (xjitter = 2) Any suggestions on how to plot this. I could create the separation in the x-axis (0,0.2,1,1.2,2,2.2). If so, how could I relable the axis ("Low","Med","High") in ggplot2. Thanks for your help. Juliet
rmailbox at justemail.net
2008-Nov-19 23:39 UTC
[R] ggplot2; dot plot, jitter, and error bars
Do ?position_jitter You will see why the error message "unused arguments" is happening in your example. ----- Original message ----- From: "Juliet Hannah" <juliet.hannah at gmail.com> To: r-help at r-project.org Date: Wed, 19 Nov 2008 18:34:36 -0500 Subject: [R] ggplot2; dot plot, jitter, and error bars With this data x <- c(0,0,1,1,2,2) y <- c(5,6,4,3,2,6) lwr <- y-1 upr <- y+1 xlab <- c("Low","Low","Med","Med","High","High") mydata <- data.frame(x,xlab,y,lwr,upr) I would like to make a dot plot and use lwr and upr as error bars. Above 0=Low. I would like there to be some space between the 5 and the 6 corresponding to Low so I tried jittering: p <- ggplot(mydata, aes(x=x, y=y)) p+geom_point() p + geom_jitter(position=position_jitter(xjitter=2)) But I obtained this error: Error in get("new", env = PositionJitter, inherits = TRUE)(PositionJitter, : unused argument(s) (xjitter = 2) Any suggestions on how to plot this. I could create the separation in the x-axis (0,0.2,1,1.2,2,2.2). If so, how could I relable the axis ("Low","Med","High") in ggplot2. Thanks for your help. Juliet ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
On Wed, Nov 19, 2008 at 5:34 PM, Juliet Hannah <juliet.hannah at gmail.com> wrote:> With this data > > x <- c(0,0,1,1,2,2) > y <- c(5,6,4,3,2,6) > lwr <- y-1 > upr <- y+1 > xlab <- c("Low","Low","Med","Med","High","High") > mydata <- data.frame(x,xlab,y,lwr,upr) > > I would like to make a dot plot and use lwr and upr as error bars. > Above 0=Low. I would like there to be > some space between the 5 and the 6 corresponding to Low so I tried jittering: > > p <- ggplot(mydata, aes(x=x, y=y)) > p+geom_point() > p + geom_jitter(position=position_jitter(xjitter=2)) > > But I obtained this error: > > Error in get("new", env = PositionJitter, inherits = TRUE)(PositionJitter, : > unused argument(s) (xjitter = 2) > > Any suggestions on how to plot this. I could create the separation in > the x-axis (0,0.2,1,1.2,2,2.2). If so, > how could I relable the axis ("Low","Med","High") in ggplot2.I think you probably want: p <- ggplot(mydata, aes(xlab, y)) p + geom_point(position = position_dodge(0.4)) but unfortunately there was a bug that prevented that from working in the current version. It'll be fixed in the next version which should be released tomorrow. Hadley -- http://had.co.nz/