【问题标题】:Putting 8 plots (4 row by 2 col) on one page在一页上放置 8 个图(4 行 x 2 列)
【发布时间】: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


【解决方案1】:

我一直在使用以下代码在一个窗口中放置 8 个图(2 行 4 列)

x<-seq(1,20,1)
y<-seq(1,20,1)
m <- rbind(c(1,2,3,4), c(5,6,7,8) )
layout(m)
par(oma = c(6, 6, 1, 1)) # manipulate the room for the overall x and y axis titles
par(mar = c(.1, .1, .8, .8)) # manipulate the plots be closer together or further apart
plot(x,y, yaxt'n') #will be in location 1 (row 1 column 1) in (m) 
plot(x,y xaxt='n', yaxt'n') #will be in location 2 (row 1 column 2) in (m)
plot(x,y xaxt='n', yaxt'n') #will be in location 3 (row 1 column 3) in (m)
plot(x,y xaxt='n', yaxt'n') #will be in location 4 (row 1 column 4) in (m)
plot(x,y) #will be in location 5 (row 2 column 1) in (m)
plot(x,y) #will be in location 6 (row 2 column 2) in (m)
plot(x,y) #will be in location 7 (row 2 column 3) in (m)
plot(x,y) #will be in location 8 (row 2 column 4) in (m)

您可以通过在每个绘图窗口中指定 xaxt='n', yaxt'n' 来控制绘图命令,例如 x 和 y 轴文本(参见上面的示例)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-29
    • 2021-02-26
    • 1970-01-01
    • 2012-04-28
    • 1970-01-01
    相关资源
    最近更新 更多