【发布时间】:2021-05-29 13:39:30
【问题描述】:
在这个thread 的帮助下,我拥有了这个norm_f() 函数。该函数生成两个图来评估正态分布:
> norm_f(iris$Sepal.Length)
函数是这样写的:
norm_f <- function(z, hist. = list(col = "lightgray"),
lines. = list(lwd = 2), curve. = list(col = "red", lwd = 2),
qqnorm. = list(col = "black", pch = 1, cex = 1.2), qqline. = list(lwd = 2)) {
zname <- deparse(substitute(z))
zden <- density(z)
if (!"ylim" %in% names(hist.)) {
ymax <- max(zden$y, dnorm(c(seq(min(z), max(z), len = 21)), mean = mean(z), sd = sd(z)))
hist.$ylim <- c(0, ymax)
}
par(mfrow=c(1,2), mar=c(5,5,2,2))
if (!"main" %in% names(hist.)) hist.$main <- paste("Histogram of", zname)
if (!"xlab" %in% names(hist.)) hist.$xlab <- zname
do.call(hist, c(list(z, prob = TRUE), hist.))
do.call(lines, c(list(zden), lines.))
do.call(curve, c(list(substitute(dnorm(x, mean=mean(z), sd=sd(z))),
add = TRUE), curve.))
do.call(qqnorm, c(list(z), qqnorm.))
do.call(qqline, c(list(z), qqline.))
}
我想更新函数,使其生成 2x2 图:两个没有 log2 变换(如上)和两个带有 log2 变换协变量的图(即,对应于 norm_f(log2(iris$Sepal.Length)))
预期输出:
【问题讨论】: