grid.arrange与R Studio中的filled.contour

我用filled.contour函数创建了一些图。 然后我想绘制两个彼此相邻的情节。 因此我使用了grid.arrange函数。 这是我的代码:

install.packages("gridExtra")
install.packages("lattice")
install.packages("grid")
library(lattice)
library(gridExtra)
library(grid)

# Fake data 
x <- c(1:10)

y <- c(1:10)
z<-matrix(data=c(1:100), nrow=10, ncol=10, byrow = FALSE)


p1<-filled.contour(x,y,z, color = terrain.colors, asp = 1) # simple


# Lay out both plots
grid.arrange(p1,p1, ncol=2)

但我得到的是:

gList中的错误(list(wrapvp = list(x = 0.5,y = 0.5,width = 1,height = 1,仅在'gList'中允许'grobs'

这就是为什么我试过这个:

install.packages("gridExtra")
install.packages("lattice")
install.packages("grid")
library(lattice)
library(gridExtra)
library(grid)

# Fake data (taken from the fill.contour help examples)
x <- c(1:10)

y <- c(1:10)
z<-matrix(data=c(1:100), nrow=10, ncol=10, byrow = FALSE)


p1<-filled.contour(x,y,z, color = terrain.colors, asp = 1) # simple
p1<-grob(p1)
is.grob(p1)


# Lay out both plots
grid.arrange(p1,p1, ncol=2)

但是这也行不通。 你能帮我吗?


正如@ eipi10指出的那样,filled.contour是基础图形,因此您应该使用基本排列函数,即par(mfrow = c(1,2))并排排列两个图。

编辑:显然充满轮廓是着名的击败所有布局尝试。 我尝试了par(plt...) layout()par(mfrow...)我找到filled.countour3作为解决方法,如下所述:

http://wiki.cbr.washington.edu/qerm/sites/qerm/images/e/ec/Example_4_panel_contour_plot_with_one_legend.R

并在此网站上提问14758391。 对困惑感到抱歉

链接地址: http://www.djcxy.com/p/30879.html

上一篇: grid.arrange with filled.contour in R Studio

下一篇: R ggplot2 saving plots as R objects and displaying in grid