0
点赞
收藏
分享

微信扫一扫

R语言与医学统计图形-【21】ggplot2标题

ggplot2绘图系统——标题

在期刊杂志中,需要设置的图形标题并不多。

除了图形标题,还有坐标轴标题(标签)、图例标题、脚注等。

  • 标题函数:​​ggtitle​​​,​​labs​
  • 坐标轴标题函数:​​xlab​​​,​​ylab​

labs的参数可以是​​title,subtitle,caption,x,y​​​,也可以是映射属性,如​​color,size,shape​​等来表示图例标题。

p <- ggplot(mtcars,aes(mpg,wt,color=factor(cyl)))+
  geom_point()
p+ggtitle(label='New plot title',subtitle = 'subtitle')+
  labs(color='legend')+ #size/shape,映射属性表示图例标题
  xlab('new x label')+
  ylab('new y label')+
  labs(caption = '(based on mtcars data)') #脚注

R语言与医学统计图形-【21】ggplot2标题_坐标轴

标题调整

通过theme函数的参数​​plot.title,plot.background,plot.margin​​。

p+labs(title='New plot title')+ labs(color='legend')+
  labs(caption = '(based on mtcars data)')+
  theme(plot.title = element_text(color = 'red',
                                  size=9,
                                  hjust=0.5),
        plot.caption = element_text(color='blue'))

R语言与医学统计图形-【21】ggplot2标题_sed_02
hjust参数取值范围0-1,0表示最左侧,1表示最右侧。


作者:Bioinfarmer

 若要及时了解动态信息,请关注同名微信公众号:Bioinfarmer。

举报

相关推荐

0 条评论