由'plot'和'ggplot'并排生成的图 [英] plots generated by 'plot' and 'ggplot' side-by-side
问题描述
有没有办法将 使用 这个例子是本博文 Dylan Beaudette Is there a way to put the plot generated by It is easy to put plots created by the same function into one page using You can do this using the This example is a modified version of this blog post by Dylan Beaudette 这篇关于由'plot'和'ggplot'并排生成的图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! ggplot
函数一页并排?
par $ c $将相同功能创建的图放入一个页面非常简单c>或
multiplot
函数,但我无法弄清楚上述问题。 您可以使用 gridBase
包和viewPorts来完成此操作。
<$ c $ b $ library(gridBase)
library(ggplot2)
#开始新页面
plot.new()
#setup layout
gl< - grid.layout(nrow = 1,ncol = 2)
#grid.show.layout(gl)
#setup viewports
vp.1< - viewport(layout.pos.col = 1,layout.pos.row = 1)
vp.2< - viewport(layout.pos.col = 2,layout.pos .row = 1)
#初始布局
pushViewport(viewport(layout = gl))
#访问第一个位置
pushViewport(vp.1)
#在fir中启动新的基础图形st视口
par(new = TRUE,fig = gridFIG())
plot(x = 1:10,y = 10:1)
#done与第一个视口
popViewport()
#移动到下一个视口
pushViewport(vp.2)
ggplotted< - qplot(x = 1:10,y = 10:1,'point')
#在这里打印我们的ggplot图形
print(ggplotted,newpage = FALSE)
#
popViewport(1)
plot
function and the plot by ggplot
function in R in one page side-by-side?par
or multiplot
function, but I can't figure out the above question.gridBase
package and viewPorts.library(grid)
library(gridBase)
library(ggplot2)
# start new page
plot.new()
# setup layout
gl <- grid.layout(nrow=1, ncol=2)
# grid.show.layout(gl)
# setup viewports
vp.1 <- viewport(layout.pos.col=1, layout.pos.row=1)
vp.2 <- viewport(layout.pos.col=2, layout.pos.row=1)
# init layout
pushViewport(viewport(layout=gl))
# access the first position
pushViewport(vp.1)
# start new base graphics in first viewport
par(new=TRUE, fig=gridFIG())
plot(x = 1:10, y = 10:1)
# done with the first viewport
popViewport()
# move to the next viewport
pushViewport(vp.2)
ggplotted <- qplot(x=1:10,y=10:1, 'point')
# print our ggplot graphics here
print(ggplotted, newpage = FALSE)
# done with this viewport
popViewport(1)