2010-10-05 149 views
28

我尝试使用+opts(subtitle="text")添加小标题,但没有显示出来。主标题确实有效(+opts(title="text"))。如何添加小标题并更改R中ggplot图的字体大小?

我还想为轴(标签和坐标)使用较大的字体,但我不知道该怎么做。

+0

对于第一个问题,有一个更好的答案在这里:http://stackoverflow.com/questions/11724311/how-to-add-a-ggplot2 -subtitle-with-different-size-and-color – naught101 2014-08-29 02:51:41

+0

将问题标记为重复的,因为有一个更新的问题对我来说看起来很奇怪。那么为什么这被标记为重复? – Jaap 2014-08-29 08:35:07

回答

45

theme_get()会告诉你,你可以在opts()使用 “隐藏” 选项,张贴0.91这是theme()

电流:

theme(axis.text.x=element_text(size=X)) 
theme(axis.text.y=element_text(size=X)) 

前0.91:

opts(axis.text.x=theme_text(size=X)) 
opts(axis.text.y=theme_text(size=X)) 

将尺寸更改为您所需的尺寸。

WRT标题,您可以使用 “\ n” 来剩余的文本移动到新行:

电流:

labs(title="text \n more text") 

前0.91:

opts(title="text \n more text") 

ggplot2没有“字幕”功能。但是,您可以使用任何标签中的\ n项来删除一行。

+1

+1太棒了! ''theme_get()' – Legend 2011-10-18 23:14:12

+3

'theme_text'现在不再使用'element_text'代替。我会说更多,但我正在寻找如何自己使用'element_text'。帮助只是一个存根。 – geneorama 2012-09-13 18:14:59

+0

尝试更新你的软件包。该文档已得到改进,我也更新了我的答案。 – 2012-09-13 18:40:39

3

更新:ggplot版本2.2.0可以做字幕,如例如,在this blog post

例子:

library(ggplot2) 
packageVersion("ggplot2") ## 2.2.0 
d <- data.frame(x=1:5,y=1:5) 
ggplot(d,aes(x,y))+ 
    labs(title="abc",subtitle="def")+ 
    ## default left-aligned: moved them to center alignment 
    theme(plot.title=element_text(hjust=0.5), 
      plot.subtitle=element_text(hjust=0.5)) 

enter image description here

相关问题