【发布时间】:2015-03-14 21:10:45
【问题描述】:
我有 8 个具有相似数据的不同回归图。我在每个图表中都有图例,例如:
1- regression model
2-95%CI
3- equation and R square
我的代码分别生成了 8 个图,但我无法仅在一页中生成它们。
数据 asf356
count ct
1 8.4 9.82
2 7.4 13.06
3 6.4 16.94
4 5.4 18.77
5 4.7 21.73
6 4.0 25.81
7 3.3 28.57
8 2.6 27.46
9 8.4 9.70
10 7.4 13.34
11 6.4 17.73
12 5.4 20.25
13 4.7 25.40
14 4.0 25.91
15 3.3 28.88
16 2.6 32.71
17 8.4 9.70
18 7.4 13.34
19 6.4 17.73
20 5.4 20.25
21 4.7 25.40
22 4.0 25.91
23 3.3 28.88
24 2.6 32.71
####ASF 356 standard curve
asf_356<-read.table("asf356.csv", head=TRUE, sep=',')
asf_356
# Multiple Linear Regression Example
fit <- lm( ct ~ count, data=asf_356)
summary(fit) # show results
predict.lm(fit, interval = c("confidence"), level = 0.95, add=TRUE)
newx <- seq(min(asf_356$count), max(asf_356$count), 0.1)
a <- predict(fit, newdata=data.frame(count=newx), interval="confidence")
plot(x = asf_356$count, y = asf_356$ct, xlab="Log(10) for total ASF 356 genome copies",
ylab="Cycle threshold value", xlim=c(0,10), ylim=c(0,35), lty=1, family="serif")
curve(expr=fit$coefficients[1]+fit$coefficients[2]*x, xlim=c(min(asf_356$count),
max(asf_356$count)), col="black", add=TRUE, lwd=2)
lines(newx,a[,2], lty=3)
lines(newx,a[,3], lty=3)
legend(x = 0.5, y = 20, legend = c("Logistic regression model", "95% individual confindence interval"), lty = c("solid", "dotdash"), col = c("black", "black"), bty = "n")
mod.fit=summary(fit)
r2 = mod.fit$r.squared
mylabel = bquote(italic(R)^2 == .(format(r2, digits = 3)))
text(x = 8.2, y = 25, labels = mylabel)
legend(x = 7, y = 35, legend =c("y= -3.774*x + 41.21"), bty="n")
【问题讨论】:
-
使用 par(mfrow=c(4,2)) 将绘图画布分成 8 个绘图。
标签: r regression linear-regression