2013-03-21 3 views
21

테마 사이에 아무 공간도 두지 않으려 고 (두 축이 공유하기 때문에) 두 개의 그림을 그려 보겠습니다.grid.arrange와 결합 된 두 ggplots 사이의 모든 공간을 제거합니다.

을 감안할 때 :

p1 <- qplot(1,1,xlab="") 

p1 <- p1 + 
    theme(legend.position="none", 
     axis.text.x=element_blank(), 
     axis.ticks.x=element_blank(), 
     plot.margin=unit(c(1,1,0,1), "cm"), 
     panel.margin=unit(c(1,1,0,1), "cm")) 
p2 <- qplot(1,2) 

grid.arrange(p1,p2) 

생산 어떤 :

enter image description here

내가 두 플롯 사이의 공백을 제거합니다.

폭이 넓어서 높이가 미세하게 조정 된 느낌이 있습니다. left align two graph edges (ggplot)은 해결책이지만이를 이해할 수는 없습니다.

+0

가능한 [grid.arrange에서 테두리 제거] (http://stackoverflow.com/questions/13728272/remove-the-orders-from-grid-arrange) – kdarras

답변

31

두 플롯에 모두 plot.margin을 입력하고 p1의 경우 하단 여백에 음수 값을 설정하고 p2의 경우에는 상위 여백을 설정해야합니다. 그러면 두 플롯 조인이 모두 보장됩니다.

p1 <- qplot(1,1,xlab="")+ 
    theme(legend.position="none", 
     axis.text.x=element_blank(), 
     axis.ticks.x=element_blank(), 
     plot.margin=unit(c(1,1,-0.5,1), "cm")) 
p2 <- qplot(1,2)+ 
    theme(legend.position="none", 
     plot.margin=unit(c(-0.5,1,1,1), "cm")) 


grid.arrange(p1,p2) 

enter image description here

1

는 grid.arrange

을 사용하기 전에 플롯 (P1, P2)의 주위에 왼쪽과 아래쪽 여백을 제거하기 위해

+ labs(x=NULL) 

또는

+ labs(x=NULL, y=NULL) 

시도
p1 <- qplot(1,1)+ 
theme_bw() + 
theme(axis.text.x=element_blank(), 
axis.ticks.x=element_blank(), 
plot.margin = rep(unit(0,"null"),4), 
panel.margin = unit(0,"null"), 
axis.ticks.length = unit(0,"null"), 
axis.ticks.margin = unit(0,"null")) + 
labs(x=NULL) 
p2 <- qplot(1,2)+ 
theme_bw() + 
theme(
plot.margin = rep(unit(0,"null"),4), 
panel.margin = unit(0,"null"), 
axis.ticks.length = unit(0,"null"), 
axis.ticks.margin = unit(0,"null")) 

grid.arrange(p1,p2) 
+2

중 하나도 좋지 않습니다. 사람들이 축 제목을 실제로 원하면 어떻게 될까요? 아니면 전설인가? 가장 좋은 옵션은 적절하게 정렬 할 수 있으며 더 일반적이며 신뢰할 수있는 솔루션을 제공하는 몇 가지 게시물이 여기에 있습니다. – baptiste

+6

더 나은 솔루션으로 연결되는 마인드? –

관련 문제