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

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

问题描述

  library(ggplot2)

my_title =这是一个很长的情节标题,我想很好地包装\\\
并适合情节而不必手动添加反斜杠n,但目前它不会

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

我们不认为有一个文字换行选项,我们不认为有文字换行选项在 ggplot2 中(我总是手动插入\\\
)。但是,您可以通过以下方式更改代码来缩小标题文本的大小:

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

实际上,您可以通过 theme_text 函数实现文本的所有方面。


library(ggplot2)

my_title = "This is a really long title of a plot that I want to nicely wrap \n 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?

解决方案

I do not think there is a text wrap option in ggplot2 (I have always just inserted \n 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))

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

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

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