Stat_qq removes values ​​when setting up a group

I am trying to make a QQ chart in ggplot2where several selected points should have a different shape. But when I bind the form to a variable in aesthetics, it stat_qqincludes this variable to separate the data (2x3 factors are involved).

Here is an example of reproducibility:

library(ggplot2)
set.seed(331)

df <- do.call(rbind, replicate(10, {expand.grid(method=factor(letters[1:3]), model=factor(LETTERS[1:2]))}, simplify=FALSE ))
df$x <- runif(nrow(df))
df$y <- rnorm(nrow(df), sd=0.2) + 1*as.integer(df$method)
df$top <- FALSE
df <- df[order(df$y, decreasing=TRUE),]
df$top[which(df$method=='a')[1:10]] <- TRUE

So far, I have managed to make a simple QQ chart:

ggplot(df, aes(sample=y, colour=method)) + stat_qq() + facet_grid(.~model)

ggplot (df, aes (sample = y, color = method)) + stat_qq () + facet_grid (. ~ model)

This is basically what I want, with the exception of a hand full of points in the 'a' method, having a different shape, which is indicated by the variable 'top'. From the code, we know that they correspond to the top 5 values ​​in the 'a' method in each model; i.e., the five remaining red dots in each face should have a different shape. Here I tried to add it as an aesthetic:

ggplot(df, aes(sample=y, colour=method, shape=top)) + stat_qq() + facet_grid(.~model)

ggplot (df, aes (sample = y, color = method, shape = top)) + stat_qq () + facet_grid (. ~ model)

, stat_qq 'top', , 5 . , .

stat_qq, ? :

ggplot(df, aes(sample=y, colour=method, shape=top, group=method)) + stat_qq() + facet_grid(.~model)
Warning messages:
1: Removed 10 rows containing missing values (geom_point). 
2: Removed 10 rows containing missing values (geom_point). 

ggplot (df, aes (sample = y, color = method, shape = top, group = method)) + stat_qq () + facet_grid (. ~ model)

- , .

, ?

+3
1

ggplot2, ggplot:

library(plyr)
df <- ddply(df, .(model, method), 
            transform, theo=qqnorm(y, plot.it=FALSE)[["x"]])

ggplot(df, aes(x=theo, y=y, colour=method, shape=top)) + 
    geom_point() + facet_grid(.~model)

enter image description here

+4

All Articles