Re: qplot

80 views
Skip to first unread message

Brandon Hurr

unread,
Sep 20, 2012, 9:32:08 AM9/20/12
to SP, ggp...@googlegroups.com
Do you have an example we could play with? 

I saw this and it might be appropriate... 
http://stackoverflow.com/questions/7962267/cbind-a-df-with-an-empty-df-cbind-fill

On Thu, Sep 20, 2012 at 2:08 PM, SP <heys...@gmail.com> wrote:
I am tyring to use theqplot function in  ggplot2 package and being fairly new to this package and R in general I am a bit stuck. I have five different datasets and every dataset has a column I am interested in plotting. What I would like is to plot these columns together in one graph. But since these columns are of different lengths  I cannot use cbind to create a new  data frame for plotting. Would you have any ideas how to get this working ?

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Ben Bond-Lamberty

unread,
Sep 20, 2012, 9:34:35 AM9/20/12
to SP, ggp...@googlegroups.com
Generally speaking, you're going to want to melt() your data, so all
the data are in a single column conditioned by a label column, and
then use qplot(). Note that melt is in the reshape package.

If you want more specific advice, please provide an example, as Brandon said.

Ben

Brandon Hurr

unread,
Sep 21, 2012, 1:52:06 PM9/21/12
to ggplot2, heys...@gmail.com
Your problem is with ecdf... not with ggplot2. I don't know how to
deal with the output from ecdf...

If you run
> ecdf(z)

You get the same error.

Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing =
decreasing)) :
undefined columns selected



---------- Forwarded message ----------
From: Sarita Paranjpe <heys...@gmail.com>
Date: Fri, Sep 21, 2012 at 2:53 PM
Subject: Re: qplot
To: Brandon Hurr <brando...@gmail.com>


Here you go (z) as my_data


On Fri, Sep 21, 2012 at 3:16 PM, Brandon Hurr <brando...@gmail.com> wrote:
>
> Can you dput(z) so we can see the structure of it and try to plot it?
>
>
> On Fri, Sep 21, 2012 at 1:55 PM, Sarita Paranjpe <heys...@gmail.com> wrote:
>>
>> Hi,
>> I hope this code makes it more easier to interpret my problem :
>> qplot(unique(l), ecdf(l)(unique(l)), geom='step') # with this command I can plot a single column and show the frequency distribution
>> To plot multiple lines (columns of unequal lengths) this is what I did :
>> a1 = as.matrix(a[,2])
>> b1 = as.matrix(b[,2])
>> c1 = as.matrix(c[,2])
>> d1 = as.matrix(d[,2])
>> e1 = as.matrix(e[,2])
>> cbind.fill<-function(...){
>> nm <- list(...)
>> nm<-lapply(nm, as.matrix)
>> n <- max(sapply(nm, nrow))
>> do.call(cbind, lapply(nm, function (x)
>> rbind(x, matrix(, n-nrow(x), ncol(x)))))
>> }
>> bound = cbind.fill(a1,b1,c1,d1,e1) # this rightfully introduced NAs to fill empty rows
>> y = data.frame(bound)
>> z = melt(y) # creates two columns of variable and value
>> qplot(unique(z), ecdf(z)(unique(z)), geom='step') # doesn't work
>>
>> ## Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing = decreasing)) :
>> undefined columns selected
>>
>> ggplot(ecdf(z), aes(x=variable, fill=variable, y=value)) + geom_line() # doesn't work same error as above.
>>
>> Thanks for all your help,
>> SP
my_data
Reply all
Reply to author
Forward
0 new messages