theme(
# title 제목 가운데 정렬plot.title= element_text(hjust=0.5),
# legend 제목 없애기legend.title= element_blank(),
# legend text sizelegend.text= element_text(size=12),
# legend 위치 (bottom, top 등)legend.position="bottom"
)
ggplot 여려 개 그리기
# p1, p2는 각각 ggplot objectgridExtra::grid.arrange(p1, p2,
nrow=1)
common legend 사용하기
# 아래의 패키지 필요!!# install.packages("ggpubr")
library(ggpubr)
fig_list<-list() # ggplot object 넣어둘 listfor (iin1:3) {
# 각자 데이터에 맞도록 개별 그림 그리기p<- ggplot(
data=df,
aes(
x=time,
y=val,
group=var_name,
color=var_name
)
) +
geom_line() +
labs(x="Days", y="") +
theme_bw() +
theme(plot.title= element_text(hjust=0.5),
legend.title= element_blank(),
legend.text= element_text(size=12),
legend.position="bottom")
# fig_list에 appendfig_list<- c(fig_list,
list(p))
}
# 아래 함수로 common legend를 가지는 그림 그리기ggpubr::ggarrange(plotlist=fig_list,
nrow=1, ncol=3,
common.legend=TRUE, legend="bottom")