我正在使用ggtext::element_textbook_simple在绘图中包含一些填充文本,因为它对长字符串的换行有很好的功能。
当我直接在markdown中运行代码时,我得到了一个很好的图,所有单词之间的间距是相等的:
```{r fig.width = 6, fig.height = 4}库(Dplyr)
库(Ggplot2)
库(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.") + 主题(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)

有没有人知道为什么会这样/我怎样才能防止这种情况发生?
发布于 2021-05-21 22:45:39
可能是图形设备的问题。我不能在我这边重现这个问题。尝试使用agg设备。
library(ragg)
agg_png("plot1.png", width = 6, height = 4, units = "in", res = 300)
print(p1)
dev.off()https://stackoverflow.com/questions/67627502
复制相似问题