gpt4 book ai didi

r - 如何在 grid.newpage 中使用 R 基图?

转载 作者:行者123 更新时间:2023-12-03 18:18:17 26 4
gpt4 key购买 nike

是否可以在 grid 中“强制”R 基图包裹的grid.newpage ?例如,这工作正常:

library(grid)
grid.newpage()
vp1 <- viewport(x=0,y=0.5,width=0.5, height=0.5, just = c("left", "bottom"))
vp2 <- viewport(x=0.5,y=0,width=0.5, height=0.5, just = c("left", "bottom"))
pushViewport(vp1)
grid.rect()
grid.text("vp1", 0.5, 0.5)
upViewport()
pushViewport(vp2)
grid.rect()
grid.text("vp2", 0.5, 0.5)

enter image description here .

但如果我尝试这样的事情:
grid.newpage()
vp1 <- viewport(x=0,y=0.5,width=0.5, height=0.5, just = c("left", "bottom"))
vp2 <- viewport(x=0.5,y=0,width=0.5, height=0.5, just = c("left", "bottom"))
pushViewport(vp1)
grid.rect()
print(plot(1,2))
grid.text("vp1", 0.5, 0.5)
upViewport()
pushViewport(vp2)
grid.rect()
print(plot(1,2))

R 基础图只是覆盖了 grid.newpage .使用 par(new=T)也没有帮助。

最佳答案

因为没有人回答这个,我会自己做。正如 Andrie 所说,这个问题的答案是 here .您需要 gridFIG()函数来自 gridBaseplot.new() 中绘制 R 基图的包而不是 grid.newpage() :

library(grid)
library(gridBase)
plot.new()
vp1 <- viewport(x=0,y=0.5,width=0.5, height=0.5, just = c("left", "bottom"))
vp2 <- viewport(x=0.5,y=0,width=0.5, height=0.5, just = c("left", "bottom"))
pushViewport(vp1)
grid.rect()
grid.text("vp1", 0.5, 0.5)
par(new=TRUE, fig=gridFIG())
plot(1,2)
upViewport()
pushViewport(vp2)
grid.rect()
grid.text("vp2", 0.5, 0.5)
par(new=TRUE, fig=gridFIG())
plot(1,2)

enter image description here

关于r - 如何在 grid.newpage 中使用 R 基图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14999802/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com