【问题标题】:Add text in between multiple plots在多个绘图之间添加文本
【发布时间】:2020-03-03 01:17:25
【问题描述】:

我正在并排绘制 5 个栅格。该图表示线性回归模型,因此该图应表示r1 ~ r2 + r3 + r4 + r5。我正在使用 par() 来排列 5 个栅格,现在想在顶部的白色间隙中添加文本符号 ~,+,+,+

多图示例:

par(mfrow = c(1,5))
plot(1, type="n", xlab="", ylab="", xlim=c(0, 10), ylim=c(0, 10))
plot(1, type="n", xlab="", ylab="", xlim=c(0, 10), ylim=c(0, 10))
plot(1, type="n", xlab="", ylab="", xlim=c(0, 10), ylim=c(0, 10))
plot(1, type="n", xlab="", ylab="", xlim=c(0, 10), ylim=c(0, 10))
plot(1, type="n", xlab="", ylab="", xlim=c(0, 10), ylim=c(0, 10))

期望的结果(在 MS Paint 中创建的示例):

【问题讨论】:

  • 当您在代码中无法弄清楚时,我非常感谢您在 Paint 中进行编辑以制作一个清晰的示例。 +1

标签: r plot graphics


【解决方案1】:

你可以使用mtext在情节的边缘写一些东西:

par(mfrow = c(1,5))
plot(1, type="n", xlab="", ylab="", xlim=c(0, 10), ylim=c(0, 10))
mtext(side = 4, line = 1, "~", cex = 5, font = 2, las = 2)
plot(1, type="n", xlab="", ylab="", xlim=c(0, 10), ylim=c(0, 10))
mtext(side = 4, line = 4, "+", cex = 5, font = 2)
plot(1, type="n", xlab="", ylab="", xlim=c(0, 10), ylim=c(0, 10))
mtext(side = 4, line = 4, "+", cex = 5, font = 2)
plot(1, type="n", xlab="", ylab="", xlim=c(0, 10), ylim=c(0, 10))
mtext(side = 4, line = 4, "+", cex = 5, font = 2)
plot(1, type="n", xlab="", ylab="", xlim=c(0, 10), ylim=c(0, 10))

这是结果

请注意,side = 4 指的是绘图的右侧。 las = 2 将文本旋转 90 度。 font = 2 指的是粗体字体。 如果您希望图之间的文本更大,可以选择cex = 4 或更大。

【讨论】:

  • 可以将ann=FALSE 添加到par(...),在这种情况下,我们可以在每个情节语句中避免xlab="", ylab=""。棘手的部分是las 不会影响plot 中的标签,但会影响mtext;否则,ylab 值可能已设置。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-15
  • 2016-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多