ggplot 그래프를지도의 지정된 위치에 배치하려고합니다. ggplot2
패키지를 선택한 이유는 grid
에 대해 더 잘 알고 있기 때문입니다. 누군가가 그러한 일에 grid
을 사용하는 방법에 대한 작은 예제를 통해 나를 도울 수 있다면, 나는 그러한 대답에 대해서도 높이 평가할 것이다. 여기 annotation_custom()을 사용하여 지정된 좌표에 여러 개의 그림을 그립니다.
# create base plot
g <- ggplot(data.frame(x=c(-104,-94), y=c(33,38)), aes(x=x, y=y)) +
geom_blank()
# create theme
tm <- theme(axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.line = element_blank(),
panel.background = element_blank(),
panel.grid = element_blank(),
panel.border = element_rect(color="grey", fill=NA),
title = element_text(size=5))
# create two plot which should be placed on the base plot
p1 <- ggplot(data.frame(x=c(-104,-94), y=c(33,38)), aes(x=x, y=y)) +
geom_point() + tm
p2 <- ggplot(data.frame(x=c(-100,-98), y=c(34,37)), aes(x=x, y=y)) +
geom_point() + tm
# place them using annotation_custom() function
a1 <- annotation_custom(grob = ggplotGrob(p1),
xmin = -104, xmax = -102,
ymin = 33, ymax = 35)
a2 <- annotation_custom(grob = ggplotGrob(p2),
xmin = -100, xmax = -98,
ymin = 35, ymax = 37)
# draw
g + a1
g + a2
g + a1 + a2
그러나 g + a1 + a2
의 경우 I 삽입 첫 번째 줄거리와 p1
제 사진을 얻었다. 무엇이 잘못 되었나요? annotation_custom()
을 사용하여 두 개 이상의 플롯을 그리는 방법은 무엇입니까?
해결 방법은 grobs를 'gTree'로 감싸는 것입니다. 'g1 = grobTree (ggplotGrob (p1)); g2 = grobTree (ggplotGrob (p2))'를 호출하고'annotation_custom'에 grobs를 사용합니다. 왜 나 한테 묻지 마! – baptiste
이 문제에 대한 설명은 https://github.com/hadley/ggplot2/issues/817을 참조하십시오. ggplot2 dev는 잠시 멈추었 기 때문에 그 문제에 대한 빠른 대응이 아닐 수도 있습니다. – baptiste