0

I can't believe why this is not working! I have the following data and code:

X=
c("13.13", "13.13", "13.23", "13.23", "12.75", "12.75", "12.75", "13.14", "12.94", "12.94", "12.94", "12.94", "13.09", "13.09", "12.97", "12.81", "12.81", "12.48", "12.48", "12.48", "12.53", "12.38", "12.38", "12.38", "13.3",  "12.52", "12.39", "12.42", "12.42", "11.89", "11.98", "11.56", "12.2",  "12.53", "12.58", "12.91", "12.25", "12.21", "12.65", "12.15")

Y=
c("13.66", "13.66", "13.74", "13.74", "13.12", "13.12", "13.12", "13.43", "13.47", "13.47", "13.47", "13.47", "13.59", "13.59", "13.44", "13.27", "13.27", "12.89", "12.89", "12.89", "13.05", "12.83", "12.83", "12.83", "13.92", "13.09", "12.86", "12.92", "12.92", "12.43", "12.48", "11.93", "12.58", "12.94", "13.04", "13.16", "12.64", "12.65", "13.04", "12.56")

grades=
c("B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "A", "A", "A", "A", "A", "A", "A", "A", "A", "C",  "C",  "C", "C", "A", "A", "B", "C", "A", "A", "B")

dat<-data.frame(x=as.numeric(X),y=as.numeric(Y))
ggplot(dat, aes(x,y,colour=grades))+ geom_point()

and I get this error:

Error: Aesthetics must either be length one, or the same length as the dataProblems:x, y
Mohammad
  • 1,078
  • 2
  • 18
  • 39
  • 1
    Please see [how to create a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for tips on including sample data. Your definitions for X, Y, and grades is not valid R code. Also, why are you putting `x` and `y` in the data.frame but not `grades`? – MrFlick Apr 16 '15 at 17:40
  • Yes you are right. I just meant these are the values. I will fix them now. Thanks – Mohammad Apr 16 '15 at 17:41
  • 1
    I just tried it and it ran fine. – Ben Apr 16 '15 at 17:48
  • Worked for me too, using `ggplot2_1.0.0` – akrun Apr 16 '15 at 18:00

1 Answers1

0

You forgot grades in your data.frame.

X=
c("13.13", "13.13", "13.23", "13.23", "12.75", "12.75", "12.75", "13.14", "12.94", "12.94", "12.94", "12.94", "13.09", "13.09", "12.97", "12.81", "12.81", "12.48", "12.48", "12.48", "12.53", "12.38", "12.38", "12.38", "13.3",  "12.52", "12.39", "12.42", "12.42", "11.89", "11.98", "11.56", "12.2",  "12.53", "12.58", "12.91", "12.25", "12.21", "12.65", "12.15")

Y=
c("13.66", "13.66", "13.74", "13.74", "13.12", "13.12", "13.12", "13.43", "13.47", "13.47", "13.47", "13.47", "13.59", "13.59", "13.44", "13.27", "13.27", "12.89", "12.89", "12.89", "13.05", "12.83", "12.83", "12.83", "13.92", "13.09", "12.86", "12.92", "12.92", "12.43", "12.48", "11.93", "12.58", "12.94", "13.04", "13.16", "12.64", "12.65", "13.04", "12.56")

grades=
c("B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "A", "A", "A", "A", "A", "A", "A", "A", "A", "C",  "C",  "C", "C", "A", "A", "B", "C", "A", "A", "B")

dat<-data.frame(x=as.numeric(X),y=as.numeric(Y))

dat$grades <- grades

ggplot(dat, aes(x,y,colour=grades))+ geom_point()
Daniel
  • 7,252
  • 6
  • 26
  • 38