어색한 레이블 위치 바로잡기
도트 플롯에서 레이블이 여전히 선과 약간 겹칩니다. 조건부 hjust 미학 속성을 사용해 레이블 위치를 더 적절하게 조정하고, 표시 형태도 바꿔 보세요.
이 연습은 강의의 일부입니다
Tidyverse로 데이터 소통하기
연습 안내
geom_text()함수 호출에서hjust미학 속성에 대해, 연도가"2006"인 레이블이면1.4, 아니면-0.4값을 주세요. 이를 위해ifelse()함수를 사용합니다.geom_text()호출에서 글꼴 크기, 패밀리, 색상을 각각3,"Bookman","gray25"로 바꾸세요. 이 값들은 데이터 기반이 아니므로aes()함수 밖에 지정해야 합니다.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Save plot into an object for reuse
ilo_dot_plot <- ggplot(ilo_data) +
geom_path(aes(x = working_hours, y = country),
arrow = arrow(length = unit(1.5, "mm"), type = "closed")) +
# Specify the hjust aesthetic with a conditional value
geom_text(
aes(x = working_hours,
y = country,
label = round(working_hours, 1),
hjust = ifelse(___)
),
# Change the appearance of the text
___ = ___,
___ = "___",
___ = "___"
)
ilo_dot_plot