English · PDF 476
在这些示例中,我使用 "\n" 手动将标签拆分成多行。另一种方法是使用 stringr::str_wrap(),根据你希望每行的字符数自动添加换行符:
"Increasing engine size related to decreasing fuel economy." %>% stringr::str_wrap(width = 40) %>% writeLines() #> Increasing engine size is related to #> decreasing fuel economy.
注意使用 hjust 和 vjust 来控制标签的对齐方式。图 22-1 展示了所有九种可能的组合。

图 22-1. hjust 和 vjust 的全部九种组合
请记住,除了 geom_text() 之外,ggplot2 中还有许多其他几何对象可用于帮助标注你的图形。以下几个思路: