I am looking for a more convenient way to get the QQ graph in ggplot2 , where the quantiles are computed for the dataset as a whole. but I can use mappings (color / shapes) for groups in the data.
library(dplyr) library(ggplot2) library(broom)
Make some data:
set.seed(1001) N <- 1000 G <- 10 dd <- data_frame(x=runif(N), f=factor(sample(1:G,size=N,replace=TRUE)), y=rnorm(N)+2*x+as.numeric(f)) m1 <- lm(y~x,data=dd) dda <- cbind(augment(m1),f=dd$f)
The main plot:
ggplot(dda)+stat_qq(aes(sample=.resid))

If I try to add color, the groups will be separated to calculate quantiles (which I don't want):
ggplot(dda)+stat_qq(aes(sample=y,colour=f))

If I use stat_qq(aes(sample=y,colour=f,group=1)) , ggplot ignores the color specification, and I return the first graph.
I need a plot where the points are located in the same way as in the first case, but colored as in the second case. I have a qqnorm based qqnorm that I can post, but I'm looking for something nicer ...
source share