[英]Adjust plot margin with coplot
使用coplot
添加标题时如何更改绘图区域的上边距? 更改par
值似乎没有效果。 我想增加上边距以在那里放置标题,但更改par(mar)
并没有像我预期的那样工作。 这是一个例子,
opar <- par(mar=c(5.1, 4.1, 20, 1))
coplot(Sepal.Length ~ Sepal.Width | Species, data=iris, columns=3,
bar.bg=c(fac="light green"), panel=panel.smooth) # mar=c(5.1, 4.1, 10, 1)
title("test", outer=TRUE)
par(opar)
您可以稍微向下移动它,使其不会“脱离边缘”:
opar <- par(mar=c(5.1, 4.1, 20, 1))
coplot(Sepal.Length ~ Sepal.Width | Species, data=iris, columns=3,
bar.bg=c(fac="light green"), panel=panel.smooth) # mar=c(5.1, 4.1, 10, 1)
title("test", line =-1, outer=TRUE)
par(opar)
使用par()
影响顶部边距空间的努力失败了,我怀疑这是硬编码边距的绘图方法之一。 事实上,这是coplot中的代码:
mar <- if (have.b)
rep.int(0, 4)
else c(0.5, 0, 0.5, 0)
oma <- c(5, 6, 5, 4)
if (have.b) {
oma[2L] <- 5
if (!b.is.fac)
oma[4L] <- 5
}
if (a.is.fac && show.given[1L])
oma[3L] <- oma[3L] - 1
opar <- par(mfrow = c(total.rows, total.columns), oma = oma,
mar = mar, xaxs = "r", yaxs = "r")
正如@42 提到的,看起来coplot
的代码包含mar
的硬编码值: https : //github.com/wch/r-source/blob/bfe73ecd848198cb9b68427cec7e70c40f96bd72/src/library/graphics/R/coplot.R#L214
另一种解决方案是将 coplot 代码复制/粘贴到您自己的脚本中并更改函数中mar
的值,但如果@42 的解决方案为您完成了这项工作,这似乎有点过分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.