我有一个现有的绘图函数(可能是由其他人编写的),它使用 mfrow 在同一图形设备上绘制多个图形。我想编辑已经绘制的图形(例如,可能为图 1 添加一条引用线)
par(mfrow = c(1, 2))
plot(1:10)
hist(1:10)
# Oh no! I want to add abline(a = 0, b = 1) to the first plot!
假设这段代码嵌套在另一个绘图函数中
PlotABunchOfStuff(1:10)
我无法修改。
我不想修改 PlotABunchOfStuff
,因为其他人拥有它,或者我只是在调试,一旦发现 bug 就不需要额外的细节。
最佳答案
使用par(mfg)
。
例如:
par(mfrow = c(2, 3))
for (i in 1:6) {
plot(i, xlim = c(0,7), ylim = c(0, 7))
}
par(mfg = c(2, 2))
points(3,3,col= "red")
par(mfg = c(1, 1))
points(3,3,col= "blue")
关于r - 如何编辑由 mfrow 拆分的 R 图形设备中的先前绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56330040/