2016-09-15 5 views
1

fill.contour 함수로 몇 개의 플롯을 만들었습니다. 그런 다음 두 개의 플롯을 서로 옆에 음모를 꾸미고 싶습니다. 따라서 grid.arrange 함수를 사용했습니다. 이 내 코드입니다 :grid.arrange with 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'는 여러분이 필요로하는 것 같은 'contourplot'과'levelplot' 함수를 가지고 있습니다. – eipi10

+0

또한 http://stackoverflow.com/questions/27929452/r-return-corrplot-as-object./#27948707을 참조하십시오. – user2957945

+0

contourplot 및 levelplot의 문제점은 filled.contour와는 다른 입력이 필요하다는 것입니다. – rsl93

답변

0

@ eipi10에서 지적했듯이 filled.contour는 기본 그래픽이므로 기본 정렬 기능 (예 : par(mfrow = c(1,2)))을 사용하여 두 개의 플롯을 나란히 배열해야합니다.

편집 : 분명히 채워진 윤곽선은 모든 레이아웃 시도를 무력화시킨 것으로 유명합니다. 나는 여기에 설명 된대로 내가 해결 방법으로 filled.countour3 발견 par(plt...)layout()par(mfrow...)을 시도 :

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

이 사이트에 질문 1천4백75만8천3백91인치 혼란에 대해 미안합니다.

+0

나는 그것을 시험해 보았다. 두 개의 별도 음모가 표시됩니다. – rsl93

+0

확인. 작동하도록 코드를 수정할 수 있습니까? 아니면 다른 예제 코드를 제공 할 수 있습니까? 나는 그것을 정말로 appriciate 할 것이다. – rsl93

+0

@ rsl93; 이 함수는'filled.contour' 함수가'plot.new()'를 반복적으로 호출하기 때문에'mfrow'를 사용할 수 없습니다. Id는 위의 링크에서 접근법을 사용할 것을 제안합니다. (ps는'p1' 객체를 코드에서 보았을 때 null이므로, 왜 결합 할 수 없습니까? 일반적으로 객체에 기본 R 음모를 지정할 수 없습니다) – user2957945