系统总结下ggplot2的主题、标度、图例设置,方便查询。

主题设置

描述 主题元素 类型
整个图形背景 plot.background element_rect()
图形标题 plot.title element_text()
图形边距 plot.margin margin()
坐标轴刻度 axis.ticks element_line()
坐标轴标题 axis.title element_text()
坐标轴标签 axis.text element_text()
直线和坐标轴 axis.line element_line()
面板背景 panel.background element_rect()
面板网格线 panel.grid element_line()
面板边界 panel.border element_rect()
图例背景 legend.background element_rect()
图例符号 legend.key element_rect()
图例标签 legend.text element_text()
图例标题 legend.title element_text()
图例边距 legend.margin margin
图例位置 legend.postion “top,” “bottom,” “left,” “right”
分面标签背景 strip.background element_rect()
条状文本 strip.text element_text()
分面间隔 panel.spacing unit

theme(element_name = element_function()) element_text(), 文本, 标签和标题的字体 element_line(), 线条, 线条或线段的颜色或线条类型 element_rect(), 矩形区域,背景矩形的颜色或者边界线条类型 element_blank() , 空白, 就是不分配相应的绘图空间,即删去这个地方的绘图元素。

标度

连续性 离散型 自定义 同一型
坐标轴标度 scale_x_continous scale_x_disctrete
坐标轴标度 scale_x_log10
坐标轴标度 scale_x_sqrt
坐标轴标度 scale_x_reverse
坐标轴标度 scale_x_date
坐标轴标度 scale_x_datetime
坐标轴标度 scale_x_time
颜色标度 scale_color_continous scale_color_disctrete scale_color_manual scale_color_identity
颜色标度 scale_color_distiller scale_color_brewer
颜色标度 scale_color_gradient scale_color_hue
颜色标度 scale_color_gradient2 scale_color_grey
颜色标度 scale_color_gradientn scale_color_viridis_d
颜色标度 scale_color_viridis_c/d
填充标度 scale_fill_continous scale_fill_disctrete scale_fill_manual scale_fill_identity
填充标度 scale_fill_distiller scale_fill_brewer
填充标度 scale_fill_gradient scale_fill_hue
填充标度 scale_fill_gradient2 scale_fill_grey
填充标度 scale_fill_gradientn scale_fill_viridis_d
填充标度 scale_fill_viridis_c
大小标度 scale_size scale_size_manual scale_size_identity
大小标度 scale_size_area
大小标度 scale_radius
透明度标度 scale_x_date scale_alpha_disctrete scale_alpha_manual scale_alpha_identity
透明度标度 scale_x_datetime
线条标度 scale_linetype scale_linetype_manual scale_linetype_identity
线条标度 scale_linetype_discrete
形状标度 scale_shape scale_shape_manual scale_shape_identity
参数列表 name limits breaks labels guide na.value values

每个标度函数内部都有丰富的参数系统

scale_colour_manual() palette = function(), limits = NULL,    ##坐标或图例的范围区间。连续性c(n, m),离散型c(“a”, “b”, “c”) name = waiver(),  ##坐标和图例的名字,如不要图例的名字,name = NULL labels = waiver(),  ##坐标和图例的间隔标签 breaks = waiver(),  ##控制显示在坐标轴或者图例上的值(元素) minor_breaks = waiver(), values = waiver(),  ##参数values 指的是(颜色、形状等)视觉属性值,要么,与数值的顺序一致;要么,与breaks提供的字符型向量长度一致;要么,用命名向量c(“数据标签” = “视觉属性”)提供

图例

连续颜色标度 非连续颜色标度
sguides(color = “colorbar”) guides(color = “legend”)
guide_colourbar() guide_legend
参数 guide_colourbar guide_legend
参数 guide_coloursteps guide_bins
图例标题 title
图例标题 title.position
图例标题 title.theme
图例标题 title.vjust
图例标题 title.hjust
图例标签 label
图例标签 abel.position
图例标签 label.theme
图例标签 label.vjust
图例标签 label.hjust
图例标签 direction
图例标签 reverse
图例箱体 size barwidth/barheight key.width/key.height
图例箱体 分箱线 nbin nrow/ncol/byrow
图例箱体 刻度线 ticks/draw.ulim/draw.lim