zoukankan      html  css  js  c++  java
  • 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)') #脚注
    

    image.png

    标题调整

    通过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'))
    

    image.png
    hjust参数取值范围0-1,0表示最左侧,1表示最右侧。

  • 相关阅读:
    实验五
    实验一
    实验四
    实验三
    实验8 SQLite数据库操作
    实验7 BindService模拟通信
    实验6 在应用程序中播放音频和视频
    实验5 数独游戏界面设计
    实验4 颜色、字符串资源的使用
    实验五 存储管理实验
  • 原文地址:https://www.cnblogs.com/jessepeng/p/12307803.html
Copyright © 2011-2022 走看看