ggplot2
및 annotation_custom
을 사용하여 플롯에 삽입하려고합니다 (플롯은 실제로 범례를 대체하기 위해 사용하는지도입니다). 그러나 facet_wrap
을 사용하여 여러 패널을 생성하지만 annotation_custom
과 함께 사용하면 각면에 플롯이 재생산됩니다. 플롯을 한 번만, 바람직하게는 플롯 영역 외부에 삽입하는 쉬운 방법이 있습니까?R -면 처리 된 ggplot2 객체에 플롯 추가 (annotation_custom 사용)
다음은 간단한 예입니다
#Generate fake data
set.seed(9)
df=data.frame(x=rnorm(100),y=rnorm(100),facets=rep(letters[1:2]),
colors=rep(c("red","blue"),each=50))
#Create base plot
p=ggplot(df,aes(x,y,col=colors))+geom_point()+facet_wrap(~facets)
#Create plot to replace legend
legend.plot=ggplotGrob(
ggplot(data=data.frame(colors=c("red","blue"),x=c(1,1),y=c(1,2)),
aes(x,y,shape=colors,col=colors))+geom_point(size=16)+
theme(legend.position="none"))
#Insert plot using annotation_custom
p+annotation_custom(legend.plot)+theme(legend.position="none")
#this puts plot on each facet!
이 다음 플롯 생산 : 어떤 도움에 감사드립니다 : 것은 내가의 라인을 따라 뭔가 더하고 싶습니다. 감사!
사실, 그런 말을한다. 'grid.arrange'가 가장 좋은 방법입니다 - 감사합니다! – jslefche