grid.arrange with filled.contour in R Studio

I created a few plots with the filled.contour function. Then I would like to plot two of the plots next to each other. Therefore I used the grid.arrange function. This is my code:

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)

But what I get is:

Error in gList(list(wrapvp = list(x = 0.5, y = 0.5, width = 1, height = 1, : only 'grobs' allowed in "gList"

Thats why I tried this:

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)

But this does not work either. Can you help me please?


As @eipi10 pointed out, filled.contour is base graphics, so you should use base arrangement functions, ie par(mfrow = c(1,2)) to arrange two plots side by side.

EDIT: apparently filled contour is famous for defeating all layout attempts. I tried par(plt...) layout() and par(mfrow...) I found filled.countour3 as a workaround as described here:

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

and in question 14758391 on this site. Sorry for the confusion

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

上一篇: 在一个页面grid.arrange函数中添加多个图

下一篇: grid.arrange与R Studio中的filled.contour