[R] data.frame, ggplot vs matplot

baptiste Auguié ba208 at exeter.ac.uk
Tue Oct 30 21:22:05 CET 2007


I've been trying to use ggplot, but I cannot seem to get my data in  
the correct form. I usually have a vector x, and a matrix y and I  
would usually use matplot(x,y) to plot the columns of y against x.

Now, if i understand correctly, I should cast x and y into a  
data.frame and do something like ggplot(x,y,data=data). I think I'm  
missing something here: do I really need to reshape y into a single  
vector, replicate x accordingly, and put both vectors in a data frame?

I've tried it, but the reshape function is still very obscure to me.  
Any help appreciated!

Small example:



legend("topleft", "(x,y)",  columns)

# the version below is not working


wide <- reshape(dataS, direction="wide",timevar=c(1:length(columns)))
dataL<-reshape(wide,direction="long") # this clearly doesn't work as  
I would have thought
qplot(x, y, data = dataL)

Best regards,


More information about the R-help mailing list