이 코드는 작동합니다 :
p1 <- ggplot(iris, aes(Sepal.Length)) +
geom_density() +
ylim(limits = c(0, 1.25))+
facet_wrap(~ Species)
p2 <- ggplot(iris, aes(Sepal.Length)) +
geom_density() +
ggtitle("") + # ad empty title as place holder
labs(y = "", x = "") + # hide axis labels
ylim(limits = c(0, 1.25)) + # y axis values should be fixed in both plots
coord_fixed(ratio=20/1) + # ratio of x- and y-axis to reduce width of plot
theme(axis.ticks.y = element_blank(), axis.text.y = element_blank(), axis.line.y = element_blank(),
plot.margin=unit(c(0,0,0.65,-10), "lines")) # margin between plots = "0.65"
나는 조금 바이올린이 결과를 단지 다른 스타일 옵션을 사용했다. 이보다 더 많은 플롯이 있다면 나는 모두에게 하나의 테마를 사용하도록 권합니다.
이미
multiplot(p1, p2, cols = 2)
를 사용하고 있는지 당신은 multiplot 기능을 사용하거나 패키지 gridExtra 그리드를 설치 한 것을 사용
grid.arrange(p1, p2, ncol=2)
희망이 도움이!
'facet_grid (~ Species, margins = TRUE)'가 여기에서 작동합니다. 그러나 일반적인 경우에, 이것은 쉬운 일이 아닙니다. 'cowplot' 패키지는 정렬을 수행하지만, 패싯이 아닌 플롯은 정렬 할 수 없습니다. – Axeman