我想用只使用 R 基础绘制一个矩形:
矩形:宽 = 2.5 厘米,高 = 1 厘米
所需的输出:
原则上 drawBox
可以做到这一点,但我正在寻找基本的 R 解决方案:
library(draw)
drawBox(x =1.5, y = 4, width = 2.5, height = 1)
答案 0 :(得分:2)
您可以先创建一个空图,然后使用基础 R 函数 rect()
:
plot(NULL, axes = FALSE, xlab = "", ylab = "", xlim = c(0, 2.5), ylim = c(0, 1))
rect(xleft = 0, xright = 2.5, ybottom = 0, ytop = 1)
答案 1 :(得分:1)
以下情况如何:
par(mar = rep(0.2,4))
plot(NA, xlim = c(0,1), ylim = c(0,1), axes = FALSE, xlab = "", ylab = "")
box()
然后将其嵌入到具有指定大小的 pdf 中。