首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ggtext格式化弄乱了ggsave

ggtext格式化弄乱了ggsave
EN

Stack Overflow用户
提问于 2021-05-21 04:28:16
回答 1查看 38关注 0票数 1

我正在使用ggtext::element_textbook_simple在绘图中包含一些填充文本,因为它对长字符串的换行有很好的功能。

当我直接在markdown中运行代码时,我得到了一个很好的图,所有单词之间的间距是相等的:

代码语言:javascript
复制
```{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",

代码语言:javascript
复制
   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",

代码语言:javascript
复制
    plot.subtitle = element_textbox_simple(size = 10, lineheight = 1, padding = margin(5, 1, 5, 1)))

p1

代码语言:javascript
复制

然而,当我使用ggsave导出具有相同尺寸的绘图时,突然我得到了许多单词的间距错误:

代码语言:javascript
复制
ggsave("plot1.png", p1, width = 6, height = 4)

有没有人知道为什么会这样/我怎样才能防止这种情况发生?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-21 22:45:39

可能是图形设备的问题。我不能在我这边重现这个问题。尝试使用agg设备。

代码语言:javascript
复制
library(ragg)

agg_png("plot1.png", width = 6, height = 4, units = "in", res = 300)
print(p1)
dev.off()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67627502

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档