R: ggplot2,我可以将绘图标题设置为环绕并缩小文本以适合绘图吗? [英] R: ggplot2, can I set the plot title to wrap around and shrink the text to fit the plot?

查看:38
本文介绍了R: ggplot2,我可以将绘图标题设置为环绕并缩小文本以适合绘图吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

library(ggplot2)

my_title = "This is a really long title of a plot that I want to nicely wrap 
 and fit onto the plot without having to manually add the backslash n, but at the moment it does not"

r <- ggplot(data = cars, aes(x = speed, y = dist))
r + geom_smooth() + #(left) 
opts(title = my_title)

我可以将情节标题设置为环绕并缩小文本以适应情节吗?

can I set the plot title to wrap around and shrink the text to fit the plot?

推荐答案

我认为 ggplot2 中没有文本换行选项(我一直只是手动插入 ).但是,您可以通过以下方式更改代码来缩小标题文本的大小:

I do not think there is a text wrap option in ggplot2 (I have always just inserted manually). You can, however, shrink the size of the title's text by altering your code in the following way:

title.size<-10
r + geom_smooth() + opts(title = my_title,plot.title=theme_text(size=title.size))

实际上,您可以使用 theme_text 函数对文本的各个方面进行操作.

In fact, you all aspects of text with the theme_text function.

这篇关于R: ggplot2,我可以将绘图标题设置为环绕并缩小文本以适合绘图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆