标签:env ring mes variable printf upload pre print f11
要做两两样本的相关性散点图,并计算标明相关系数。
编写函数要点:
方法1:用!!ensym
myplot <- function(indata, inx, iny){
nms <- names(indata)
x <- nms[inx]
y <- nms[iny]
regression <- paste0(x, " ~ ", y)
dat.lm <- lm(as.formula(regression), data = indata)
r <- sprintf("italic(r) == %.2f",sqrt(summary(dat.lm)$r.squared))
labels <- data.frame(r=r,stringsAsFactors = FALSE)
ggplot(indata,aes(x=!!ensym(x), y=!!ensym(y)))+geom_point() +
geom_smooth(method = lm) +
labs(x=paste0(x," (log2 intensity)"),y=paste0(y," (log2 intensity)")) +
geom_text(data=labels,mapping=aes(x = 15,y=30,label=r),parse = TRUE,inherit.aes = FALSE,size = 6)
}
p1 <- myplot(indata=dia,inx=2,iny=3)
方法2:用environment
showplot1<-function(indata, inx, iny) {
dat <- indata
p <- ggplot(dat, aes(x=dat[,inx], y=dat[,iny]), environment = environment())
p <- p + geom_point()
print(p)
}
showplot1(dia,2,3)
方法3:用aes_string
showplot1 <- function(indata, inx, iny) {
x <- names(indata)[inx]
y <- names(indata)[iny]
p <- ggplot(indata, aes_string(x = x, y = y))
p + geom_point()
}
showplot1(dia,2,3)
两两样本的相关性散点图可以用循环生成组合图。不赘述。
Ref: https://stackoverflow.com/questions/15323269/addressing-x-and-y-in-aes-by-variable-number
标签:env ring mes variable printf upload pre print f11
原文地址:https://www.cnblogs.com/jessepeng/p/12787598.html