动态包装和/或缩小可变宽度字体标题和标签以适应ggplot2

时间:2017-10-12 09:02:47

标签: r ggplot2

我正在以自动方式(针对调查的代码簿)生成大量ggplots。其中一些情节有很长的情节标题(通常是调查问题)和/或x轴标签。

library(ggplot2)
qplot(1:10,rnorm(10)) + 
ggtitle("this is indeed a very long title but sometimes necessary. this is indeed a very long title but sometimes necessary. this is indeed a very long title but sometimes necessary", subtitle = "the very long title has an even longer subtitle to boot, really much longer than the title. the very long title has an even longer subtitle to boot, really much longer than the title.") + 
scale_x_continuous(breaks = 1:10, labels = paste("Option", 1:10))

有没有办法阻止这些文字被剪裁(通过包裹或收缩或旋转它们)?一种可以自动化并适用于可变宽度字体的方法?类似questions存在,但解决了旧版本的ggplot2,手动解决方案或facets(看起来更复杂,但label_wrap_gen似乎处理得很好,所以我想一个简单的解决方案标题也可能存在。)

在绘制之前我控制并知道绘图的宽度和高度(通过knitr chunk设置)。

我知道我可以使用\nstrwrap来换文字,但是我必须手动选择手动的切割点,并为变宽度<< / strong>字体经常留空空间。

clipped text on plot

0 个答案:

没有答案