纠正不佳的标签位置
这些标签仍然有些与点图中的连线重叠。请使用带条件的 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