Juliet Hannah
2009-Feb-08 03:25 UTC
[R] how to make this qq plot in lattice and/or ggplot2
Hi Group, Here is some data. p <- runif(1000) # sample data groups <- rep(c(1,2),each=500) #conditioning variable mydata <- cbind(p,groups) n <- length(p) u <- (1:n)/(n + 1) # uniform distribution reference for qqplot logp <- -log(p,base=10) logu <- -log(u,base=10) qqplot(logp,logu) How can I make the above qqplot in lattice and/or ggplot2. The sample is uniform, and I take -log10. In addition, I would like to use the group variable to condition. I was not able to get the stat_qq function in ggplot2 to work. Thanks for your time. Regards, Juliet
Deepayan Sarkar
2009-Feb-08 07:18 UTC
[R] how to make this qq plot in lattice and/or ggplot2
On 2/7/09, Juliet Hannah <juliet.hannah at gmail.com> wrote:> Hi Group, > > Here is some data. > > p <- runif(1000) # sample data > groups <- rep(c(1,2),each=500) #conditioning variable > mydata <- cbind(p,groups) > n <- length(p) > u <- (1:n)/(n + 1) # uniform distribution reference for qqplot > logp <- -log(p,base=10) > logu <- -log(u,base=10) > qqplot(logp,logu) > > How can I make the above qqplot in lattice and/or ggplot2. The sample > is uniform, and I take -log10. In addition, I would like to use > the group variable to condition. I was not able to get the stat_qq > function in ggplot2 to work.With lattice: library(lattice) qqmath(~ -log(p), data = as.data.frame(mydata), distribution = qexp) qqmath(~ -log(p) | factor(groups), data = as.data.frame(mydata), distribution = qexp) -Deepayan
hadley wickham
2009-Feb-08 14:12 UTC
[R] how to make this qq plot in lattice and/or ggplot2
On Sat, Feb 7, 2009 at 9:25 PM, Juliet Hannah <juliet.hannah at gmail.com> wrote:> Hi Group, > > Here is some data. > > p <- runif(1000) # sample data > groups <- rep(c(1,2),each=500) #conditioning variable > mydata <- cbind(p,groups) > n <- length(p) > u <- (1:n)/(n + 1) # uniform distribution reference for qqplot > logp <- -log(p,base=10) > logu <- -log(u,base=10) > qqplot(logp,logu) > > How can I make the above qqplot in lattice and/or ggplot2. The sample > is uniform, and I take -log10. In addition, I would like to use > the group variable to condition. I was not able to get the stat_qq > function in ggplot2 to work.With ggplot2: qplot(sample = -log(p), distribution = qexp) qplot(sample = -log(p), distribution = qexp, colour = factor(group)) However, the major caveat is that this doesn't work in the released version, but does in the development version, which I can send you off list if you tell me what operating system you use. Hadley -- http://had.co.nz/