tags:

views:

83

answers:

2

I generate a QQ plot to compare the distribution of my ranom number generator with a beta distribution. I can do this using the usual plot commands in R via

samples1 <- read.csv("test1-clean.dat")
qqplot( samples1$p0, qbeta(seq(0,1,length=length(samples1$p0)),1,3) )
abline( 0, 1 )

but I want to use the ggplot2 library, and I just cannot get my head around the documentation (I am a n00b when it comes to R)

I tried

qplot( sample = p0, data = samples1 ) + stat_qq( distribution = qbeta, seq(0,1,length=length(samples1$p0)), 1, 3 )

but that leads to an error of the form

Error: ggplot2 doesn't know how to deal with data of class numeric

Any suggestions? Also, good references on learning R would be great (I am familiar with C, C++, Matlab, etc, but R seems a bit odd to me right now)

Update:

As suggested below, I tried

params = list(shape1 = 1, shape2 = 3, lower.tail = TRUE, log.p = FALSE)

qplot( sample = p0, data = samples3 ) + stat_qq( distribution = qbeta, dparams = params )

This still does not seem to work. The error I get is

Error in function (p, shape1, shape2, ncp = 0, lower.tail = TRUE, log.p = FALSE)  : 
  element 2 is empty;
   the part of the args list of '.Internal' being evaluated was:
   (p, shape1, shape2, lower.tail, log.p)

I tried adding lower.tail and log.p into params, as well as the list of probabilities p, but that did not change the error message.

+1  A: 

There have been a number of good suggestions here on Stack Overflow for learning R. Here's a few.

you can search for all questions tagged r in Stack Overflow by adding [r] to your search string. So for the link above I searched on [r] learning

I'll let someone who uses ggplot2 more than I do answer your ggplot question.

JD Long
+4  A: 

I think I've worked it out. You need to pass the distribution parameters as a list of named values to dparams in stat_qq(). For your data, that would be (if I understood your qbeta() call)

params = list(shape1 = 1, shape2 = 3)

ggplot(samples1, aes(sample = p0))+
   stat_qq(distribution = qbeta, dparams = params)
JoFrhwld
This still does not seem to work (see update above). I am curious, though: where did you find information about dparams? I can't find anything about it in the docs.
Marcus P S
Check out `?stat_qq` towards the bottom for use of `dparams`. As for the new error, I would try using `ggplot()` instead of `qplot()` and see if that clears it up. You might also need to update `ggplot2`. Other than that, I can't recreate your error without your data.
JoFrhwld
You were right. I needed to update R in order to get the latest version of `ggplot2`, and then everything works. The earlier version did not have support for `dparams`. Thanks!
Marcus P S