R图上方图例的确切位置

时间:2017-03-28 13:39:02

标签: r plot position margin legend

我想在图表的右上方生成一个带有图例的简单图表(见下图,左图)。我可以通过使用以下简单示例来实现此目的:

par(mar = c(4, 4, 1.5, 4))
plot(rnorm(50))
par(oma = c(0, 0, 0, 0), mar = c(0, 0, 0, 4), new = TRUE)
plot(0, 0, type = "n", bty = "n", axes = F)
legend(x = "topright", "data", bty = "n", pch = 1, xpd = T, horiz = T)

当我将此绘图缩放到不同的大小时,图例有时会重叠绘图区域(右图)。 Plot in different sizes. Note the legend overlapping the plot area on the right side of the figure.

如何针对不同的绘图尺寸(或宽度/高度比)实现重叠图例?我非常感谢这个问题的帮助!

0 个答案:

没有答案