r - 在多个绘图之间添加文本

标签 r plot graphics

我正在并排绘制 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))

Example with empty plots

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

最佳答案

您可以使用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 或什至更大。

关于r - 在多个绘图之间添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58732125/

相关文章:

r - 计算每个组的 data.table 窗口中的值数量

R Shiny 的绘图颜色有条件地基于单独数据框上的值

r - 是否可以使用自定义图片作为条形图中的条形?

python - 不能根据数据在现有图上绘制计算的质心值

python - 在极坐标的两条线之间填充

python - 在 Windows 上使用 PyCharm 的 matplotlib 不会绘制图形,没有错误

java - Java 中的 Math.sin 和 Math.cos 发生了什么?以及如何修复它?

r - 来自共享公共(public)属性(唯一且一对一)的两个 sf 对象的相交多边形

android - 使用方法 -canvas.drawBitmap(bitmap, src, dst, paint)

java - 检测 SurfaceView 上绘制的 View 的触摸