나만의 테마 함수 정의하기
영상에서 코드 덩어리를 함수 호출로 바꾸면 타이핑을 크게 줄일 수 있다는 점을 보셨죠. 함수가 보통 어떻게 정의되는지도 확인했으니, 이제 이를 적용해서 이전에 사용한 두 개의 theme() 호출을 재사용 가능하게 만들어 봅시다.
이 연습은 강의의 일부입니다
Tidyverse로 데이터 소통하기
연습 안내
- 방금 익힌 함수 정의 방법을 사용해, 테마 설정을 담는
theme_ilo()함수를 만드세요. - 함수 본문에는 보통 그래프 객체에 바로 적용하던 두 호출이 모두 들어가야 해요:
theme_minimal()+ 커스터마이즈한theme(). - 샘플 코드에 제공된
theme()설정을 그대로 활용해, 이전에 하신 작업을theme_ilo()함수 안으로 옮겨 적으세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# For a starter, let's look at what you did before: adding various theme calls to your plot object
ilo_plot +
theme_minimal() +
theme(
text = element_text(family = "Bookman", color = "gray25"),
plot.subtitle = element_text(size = 12),
plot.caption = element_text(color = "gray30"),
plot.background = element_rect(fill = "gray95"),
plot.margin = unit(c(5, 10, 5, 10), units = "mm")
)
# Define your own theme function below
theme_ilo <- function() {
___() +
___(
___
)
}