2016-09-15 40 views
1

我用filled.contour函數創建了一些圖。然後我想繪製兩個彼此相鄰的情節。因此我使用了grid.arrange函數。 這是我的代碼:grid.arrange with filled.contour in R Studio

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(名單(wrapvp =列表(x = 0.5,Y = 0.5,寬度= 1,高度 = 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) 

但是這也行不通。你能幫我嗎?

+0

'filled.contour'是一個基本的圖形函數,而不是一個'lattice'函數,並且不會產生一個grob或一個可以變成grob的對象(雖然也許可以把它變成通過'gridBase'包中的函數進入grob)。如果輸入'p1 <-filled.contour(x,y,z,color = terrain.colors,asp = 1)',然後鍵入'p1',則輸出爲NULL。 'lattice'具有可能是你需要的'contour','contourplot'和'levelplot'功能。 – eipi10

+0

也見http://stackoverflow.com/questions/27929452/r-return-corrplot-as-object./#27948707 – user2957945

+0

我與contourplot和levelplot的問題是事實,他們需要與filled.contour不同的輸入。 – rsl93

回答

0

As @ 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。對不起,混淆

+0

我試過了。你會收到兩張獨立的地塊,而不是兩張都有。 – rsl93

+0

好的。你可以修改我的代碼,以使其工作,或者你可以給我另一個示例代碼?我會真正appriciate。 – rsl93

+0

@ rsl93;我的道歉,你不能在這種情況下使用'mfrow'作爲函數'filled.contour'通過它重複'plot.new()'調用。 Id建議使用上面給出的鏈接的方法(如果你在代碼中查看'p1'對象,它是空的,因此爲什麼你不能合併它們:通常你不能將一個基本的R圖分配給一個對象) – user2957945