我正在尝试使用R中的标准绘图命令堆叠3个图。到目前为止,我已经实现了以下内容:
使用以下数据:
t30DC_diff = c(12, 10, 8, 6, 4, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 6)
t50DC_diff = c(14, 16, 12, 10, 8, 6, 4, 4, 4, 4, 2, 4, 4, 6, 4, 6, 6, 6, 8, 6)
t90DC_diff = c(24, 24, 26, 22, 28, 24, 20, 20, 20, 18, 18, 18, 18, 16, 18, 14, 16, 16, 18, 16)
t30DC_sd = c(3.45, 2.62, 2.23, 1.93, 1.3, 1.03, 0.98, 0.78, 0.58, 0.9, 0.98, 0.98, 0.78, 0.85, 1.24, 1.44, 1.44, 1.59, 1.59, 1.73)
t50DC_sd = c(4.52, 4.79, 3.67, 3.09, 2.23, 1.78, 1.73, 1.34, 1.48, 1.51, 0.9, 1.59, 1.44, 1.51, 1.34, 2.23, 2.26, 2.26, 2.33, 2.15)
t90DC_sd = c(7.65, 7.88, 9.84, 7.14, 7.33, 6.82, 6.26, 6.16, 6.02, 5.66, 5.21, 5.66, 5.42, 5.25, 5.15, 4.6, 5.29, 5.22, 5.56 , 5.08)
和以下代码:
par(mfrow = c(3,1),
mar = c(0, 2.7, 3, 2.5),
mgp = c(1.7,0.6,0))
plot(t30DC_diff, pch = 16, col = "blue",
xlab = "Depth (mm)", ylab = "Time (ns)",
main = "", cex.lab = 1.2,
ylim = c(0, max(t30DC_diff) + 2),
xlim = c(0,21),
xaxs = 'i', yaxs = 'i',
cex.axis = 0.75,
xaxt = 'n',
cex.lab = 0.9)
points(t30DC_sd, pch = 4, col = "black")
legend("top",
pch = c(16,4),
col = c("blue", "black"),
legend = c("Largest Difference", "Standard Deviation"),
cex = 0.9,
horiz = T)
par(mar = c(0, 2.7, 0, 2.5))
plot(t50DC_diff, pch = 16, col = "blue",
xlab = "Depth (mm)", ylab = "Time (ns)",
main = "", cex.lab = 1.2,
ylim = c(0, 18),
xlim = c(0,21),
xaxs = 'i', yaxs = 'i',
xaxt = 'n', yaxt = 'n',
cex.axis = 0.75,
cex.lab = 0.9)
axis(side = 2,
las = 1,
at = seq(0,16,2),
cex.axis = 0.75)
points(t50DC_sd, pch = 4, col = "black")
par(mar = c(3, 2.7, 0, 2.5))
plot(t90DC_diff, pch = 16, col = "blue",
xlab = "Depth (mm)", ylab = "Time (ns)",
main = "", cex.lab = 1.2,
ylim = c(0, 30),
xlim = c(0,21),
xaxs = 'i', yaxs = 'i',
cex.axis = 0.75,
cex.lab = 0.9,
yaxt = 'n')
axis(side = 2,
las = 1,
at = seq(0,25,5),
cex.axis = 0.75)
points(t90DC_sd, pch = 4, col = "black")
我试图让中间的情节与其他两个情节具有相同的高度。关于如何做到这一点的任何想法?
感谢用户@rawr的回答,有效的新代码是:
par(mfrow = c(3,1),
mar = c(0, 2.7, 0, 2.5),
mgp = c(1.7,0.6,0),
oma = c(3, 0, 3, 0))
plot(t30DC_diff, pch = 16, col = "blue",
xlab = "Depth (mm)", ylab = "Time (ns)",
main = "", cex.lab = 1.2,
ylim = c(0, max(t30DC_diff) + 2),
xlim = c(0,21),
xaxs = 'i', yaxs = 'i',
cex.axis = 0.75,
xaxt = 'n',
cex.lab = 0.9)
points(t30DC_sd, pch = 4, col = "black")
legend("top",
pch = c(16,4),
col = c("blue", "black"),
legend = c("Largest Difference", "Standard Deviation"),
cex = 0.9,
horiz = T)
plot(t50DC_diff, pch = 16, col = "blue",
xlab = "Depth (mm)", ylab = "Time (ns)",
main = "", cex.lab = 1.2,
ylim = c(0, 18),
xlim = c(0,21),
xaxs = 'i', yaxs = 'i',
xaxt = 'n', yaxt = 'n',
cex.axis = 0.75,
cex.lab = 0.9)
axis(side = 2,
las = 1,
at = seq(0,16,2),
cex.axis = 0.75)
points(t50DC_sd, pch = 4, col = "black")
plot(t90DC_diff, pch = 16, col = "blue",
xlab = "Depth (mm)", ylab = "Time (ns)",
main = "", cex.lab = 1.2,
ylim = c(0, 30),
xlim = c(0,21),
xaxs = 'i', yaxs = 'i',
cex.axis = 0.75,
cex.lab = 0.9,
yaxt = 'n')
axis(side = 2,
las = 1,
at = seq(0,25,5),
cex.axis = 0.75)
points(t90DC_sd, pch = 4, col = "black")
这个输出是: