본문 바로가기
R 프로그래밍/R 데이터 시각화

[R 그래픽스] 제목(Title) 달기

by 찐남 2022. 1. 23.
R Graphics Cookbook을 기반으로 하여 작성하였습니다.

 

그래프에 제목(Title)을 달고 싶으면,
어떻게 해야 할까요?

 

우선, 제목이 없는 그래프의 예시입니다.

library(ggplot2)
bp <- ggplot(PlantGrowth, aes(x=group, y=weight)) + geom_boxplot()
bp

 

 

제목(Title)을 달면,

bp + ggtitle("Plant growth")
# 혹은
bp + labs(title="Plant growth") 

# 제목이 길면 \n을 사용하여 여러 줄로 나누어서....
bp + labs(title = "Plant growth with\ndifferent treatments")

# 줄 간격을 줄이고 굵은 텍스트 사용
bp + labs(title = "Plant growth with\ndifferent treatments") + 
       theme(plot.title = element_text(lineheight=.8, face="bold"))

 

반응형

댓글