开发者

ggplot2 and QQ plot for non-Gaussian distribution

开发者 https://www.devze.com 2023-01-12 07:13 出处:网络
I generate a QQ plot to compa开发者_C百科re the distribution of my ranom number generator with a beta distribution. I can do this using the usual plot commands in R via

I generate a QQ plot to compa开发者_C百科re 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.


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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消