[英]Adjust plot margin with coplot
How does one change the upper margin of the plotting region when using coplot
to add a title?使用coplot
添加标题时如何更改绘图区域的上边距? Changing the par
values doesn't seem to have an effect.更改par
值似乎没有效果。 I want to increase the upper margin to put a title there, but changing par(mar)
isn't working as I expected it to.我想增加上边距以在那里放置标题,但更改par(mar)
并没有像我预期的那样工作。 Here is an example,这是一个例子,
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)
You can move it down slightly so that it is not "off the edge":您可以稍微向下移动它,使其不会“脱离边缘”:
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)
Efforts to affect the space on the top margin failed with par()
and I suspect that this is one of the plot methods that hard-codes margins.使用par()
影响顶部边距空间的努力失败了,我怀疑这是硬编码边距的绘图方法之一。 In fact, here's the code in coplot:事实上,这是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")
As @42 mentions it looks like the code of coplot
contains a hard coded value of mar
: https://github.com/wch/r-source/blob/bfe73ecd848198cb9b68427cec7e70c40f96bd72/src/library/graphics/R/coplot.R#L214正如@42 提到的,看起来coplot
的代码包含mar
的硬编码值: https : //github.com/wch/r-source/blob/bfe73ecd848198cb9b68427cec7e70c40f96bd72/src/library/graphics/R/coplot.R#L214
An alternative solution is to copy/paste the coplot code into your own script and change the value of mar
in the function, but that seems like overkill if the solution by @42 does the job for you.另一种解决方案是将 coplot 代码复制/粘贴到您自己的脚本中并更改函数中mar
的值,但如果@42 的解决方案为您完成了这项工作,这似乎有点过分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.