Debbie Smith
2012-Apr-05 15:08 UTC
[R] ggplot2 error: arguments imply differing number of rows
This example is from "The R Book" by Michael J. Crawley. d=read.table( "http://www.bio.ic.ac.uk/research/mjcraw/therbook/data/diminish.txt" ,header=TRUE) p=qplot(xv,yv,data=d); p m1=lm(yv~xv,data=d) p1=p + geom_abline(intercept=coefficients(m1)[1], slope=coefficients(m1)[2] ); p1 m2=lm(yv~xv + I(xv^2),data=d) x=seq(min(d$xv),max(d$xv),length=100) p1 + geom_line(aes(x=x,y=predict(m2,list(xv=x))), color="red") I can run the above codes without any problems in an older version of R(R 2.10.1). But if I run the codes in a newer version of R(R 2.15, R 2.14), I got the error:> p1 + geom_line(aes(x=x,y=predict(m2,list(xv=x))), color="red")Error in data.frame(evaled, PANEL = data$PANEL) : arguments imply differing number of rows: 100, 18 I am confused about this error. Could someone help me? Thank you so much! Debbie
As you got the error message, to use ggplot function, you had better make a data.frame with your data "d". for example, d[ n x p], n : observations, p : variables n = dim(d) dd = data.frame(x=d[,2:n[2]], y=d[,1]) then, you may get the better result after apply "dd" to the ggplot function.> p1 + geom_line(aes(x=x,y=predict(m2,list(xv=x))), color="red")Error in data.frame(evaled, PANEL = data$PANEL) : arguments imply differing number of rows: 100, 18 This example is from "The R Book" by Michael J. Crawley. -- View this message in context: http://r.789695.n4.nabble.com/ggplot2-error-arguments-imply-differing-number-of-rows-tp4535261p4535432.html Sent from the R help mailing list archive at Nabble.com.