[英]Q-Q plot facet wrap with QQ line in R
如何為某些數據生成顯示 qqlines 的 qqnorm 的分面包裝?
這個問題產生了 qqplot,但沒有在圖上繪制真正的 qqline(只有數據的平滑 lm)。 代碼是從鏈接的問題中復制的。
library(plyr)
# create some data
set.seed(123)
df1 <- data.frame(vals = rnorm(1000, 10),
y = sample(LETTERS[1:3], 1000, replace = TRUE),
z = sample(letters[1:3], 1000, replace = TRUE))
# calculate the normal theoretical quantiles per group
df2 <- ddply(.data = df1, .variables = .(y, z), function(dat){
q <- qqnorm(dat$vals, plot = FALSE)
dat$xq <- q$x
dat
}
)
# plot the sample values against the theoretical quantiles
ggplot(data = df2, aes(x = xq, y = vals)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
xlab("Theoretical") +
ylab("Sample") +
facet_grid(y ~ z)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.