我ggtext::element_textbook_simple
习惯在情节中包含一些填充文本,因为它具有围绕长字符串自动换行的强大功能。
当我直接在 markdown 中运行代码时,我得到了一个很好的图,所有单词之间的间距均匀:
```{r fig.width = 6, fig.height = 4}
library(dplyr)
library(ggplot2)
library(ggtext)
p1 <- mtcars %>%
ggplot(aes(x = wt, y = hp)) +
geom_point() +
labs(title = "This is a Generic Title",
subtitle = "The theme song and opening sequence set the premise of the show. Will Smith is a street-smart teenager, West Philadelphia born and raised. While playing street basketball, Will misses a shot and the ball hits a group of gang members, causing a confrontation that frightens his mother, who sends him to live with his wealthy aunt and uncle in the opulent neighborhood of Bel Air, Los Angeles. Will's working class background ends up clashing in various humorous ways with the upper class world of the Banks family – Will's uncle Phil and aunt Vivian and their children, Will's cousins: spoiled Hilary, pompous Carlton, and impressionable Ashley.") +
theme(plot.title.position = "plot",
plot.subtitle = element_textbox_simple(size = 10, lineheight = 1, padding = margin(5, 1, 5, 1)))
p1
```
然而,当我用ggsave
相同的尺寸导出绘图时,突然间我得到了很多间距错误的单词:
ggsave("plot1.png", p1, width = 6, height = 4)
有谁知道为什么会这样/我如何防止这种情况发生?