我正在绘制以下图像:
使用此代码:
par(mfrow = c(2, 2),
mar = c(2, 2, 2, 2))
plot(1, col = "red", pch = 15)
plot(1, col = "blue", pch = 15)
plot(1, col = "orange", pch = 15)
plot(1, col = "purple", pch = 15)
我想使用
grImport
添加外部 postscript 文件(包括示例数据):
library(grImport)
#PostScriptTrace("drawing.ps")
#pic <- readPicture("drawing.ps.xml")
# generated with dput()
pic <- new("Picture",
paths = list(path = new("PictureFill", rule = "nonzero",
x = c(move = 0, line = 1315.47, line = 1315.47, line = 0,
line = 0),
y = c(move = 1080, line = 1080, line = 7.37891,
line = 7.37891, line = 1080),
rgb = "#D0D1E6", lty = numeric(0),
lwd = 10, lineend = 1, linejoin = 1, linemitre = 10)),
summary = new("PictureSummary",
numPaths = 1, xscale = c(xmin = 0, xmax = 1315.47),
yscale = c(ymin = 7.37891, ymax = 1080)))
grid.picture(pic)
这只是将 ps 图像填充到整个绘图设备:
我希望紫色方块恰好绘制在其中一个绘图区域的顶部(假设在左上角)。
如何提取整个设备参考系中第一个
plot()
的坐标?
一旦有了这些,如何正确使用
grid.picture()
中的坐标?
可能来不及提供帮助,但是,作为起点,您可以使用
picture()
而不是 grid.picture()
,例如...
mar = c(2, 2, 2, 2))
plot(1, col = "red", pch = 15)
usr <- par("usr")
picture(pic, usr[1], usr[3], usr[2], usr[4])
plot(1, col = "blue", pch = 15)
plot(1, col = "orange", pch = 15)
plot(1, col = "purple", pch = 15)
这会扭曲导入的图像以填充绘图区域,但如果这是一个问题,则可以做更多的工作来改进该解决方案。