데이터 시각화

여러 그래프에 라벨 달기 (egg)

r-code-for-data-analysis 2023. 5. 30. 09:14

논문 등에 그래프를 게재하려면 여러 그래프에 라벨을 달아야 한다. 

이때 유용하게 사용할 수 있는 패키지는 "egg" 이다. 

 

https://github.com/baptiste/egg

 

GitHub - baptiste/egg: (fragile) extensions for ggplot2

(fragile) extensions for ggplot2. Contribute to baptiste/egg development by creating an account on GitHub.

github.com

 

1. 결과

 

 

2. 패키지 설치

library(ggdensity)
library(egg)

 

3 왼쪽 상단에 라벨을 다는 경우와 오른쪽 상단에 다는 경우

g1 <- mpg %>% ggplot(aes(displ,hwy,fill=class)) + 
  geom_hdr(probs=c(0.9,0.5), alpha=0.5)+
  
  geom_point(shape=21, size=3)+
  scale_fill_tq()+
  theme_tq()+
  facet_wrap(~class)
  
  #왼쪽 상단에 라벨
  tag_facet(g1)
  
  #오른쪽 상단에 라벨
  tag_facet(g1, x = Inf, y = Inf, 
          hjust = 1.5)

 

728x90
반응형