R语言杂记R plot生信

ggplot2小结

2021-01-08  本文已影响0人  leoxiaobei

相关包

主题相关包:
ggthemes
ggthemr
cowplot
ggsci
ggtech
gplots
viridis
Rcolorbrewer
ggedit 主题编辑
esquisse GUI,交互
ggThemeAssist 主题,交互

拓展包:
ggforce(geom_sinaplot)渣浪(散点)图
ggforce 局部放大
ggVennDiagram 韦恩图
ggvenn 韦恩图
ggupset 韦恩图
ggpubr 统计
ggsignif 统计
ggstatsplot 统计
ggcorrplot 相关性
ggalluvial 冲击图
gganatogram 解剖图
ggbeeswarm 散点
ggdendro 树图
ggtree 进化或聚类树图
ggRandomForests 随机森林
ggrepel 解决字体重叠
ggridges 峰峦图
ggvegan 微生物环境因子排序
ggh4x 多分面
survminer 生存分析
gghalves 云雨图
gggenes 基因
cowplot 拼图
patchwork 拼图
aplot 对齐拼图(好使)
gganimate 动图
ggwordcloud 词云
plotROC ROC曲线
pROC(ggroc)ROC曲线
gg.gap 截断坐标轴
ggrader 雷达图
ggord 各种排序
ggbipolt PCA
autoplot PCA
FactoMineR和factoextra 各种排序
gglayer 添加圆形置信区间
ggannotate 交互式修图
ggtern 三元图
ggplotify 转换图对象为ggplot2对象
ggsymbol 拓展点图样式
ggstar 拓展点图样式
ggchicklet 圆角条形图
gggibbous 月相点图
ggcor 目前只能在github上找,做相关性的
rayshade 2D变3D
ggmsa 使用ggplot2绘制多序列比对
plotly 火山图动起来

散点:geom_point, 
      geom_jitter, 
      geom_dotplot, 
      geom_beeswarm, 
      geom_quasirandom
柱状:geom_bar (count,统计某一变量出现的次数,此时只需要x
                或直接提供y值作为其次数,此时需要x和y)
      geom_col (stack,统计某一变量的累加和,此时x为变量,y为变量数目
                 或identity,画在x下的各个y,柱子间存在遮盖,改透明度可以看到,不改只能看到最大值
                 或fill,或在x下的各个y所占比例,总的为1)
折线:geom_line
密度:geom_density
云雨:geom_flat_violin,
      gghalves::geom_half_violin
箱线:geom_boxplot
小提琴:geom_violin
热力图(方块):geom_tile
人体/动物解剖图:gganatogram
划线:geom_segment, 
      geom_vline, 
      geom_hline,
      geom_abline
文本:annotate,
      labs,
      geom_text (文本), 
      geom_label (矩形)
置信区间:geom_ord_ellipse
转化为ggplot对象:as.ggplot
误差棒:geom_pointrange, 
        geom_linerange, 
        geom_errorbar
统计: stat_compare_means(comparisons = my_comparisons), #指定组别,可进行多个俩俩比较
        stat_compare_means(aes(group = variable2))#适合第二个变量只有2个分组(实际p值),有3个以上时为全局p值,无论分不分面
        stat_compare_means(),#只有2个分组时为实际p值,3个以上分组为全局p值
        geom_signif(comparisons = my_comparisons)#指定组别,俩俩比较的p值
        geom_signif(annotations = c("NS", "*"),#由自己给出显著性
                    y_position = c(30, 40), 
                    xmin=c(4,1), 
                    xmax=c(5,3))

主题

主题:theme_gray (默认), 

theme_bw (背景色无,网格在,全坐标轴), 

theme_test (背景色无,网格无,全坐标轴), 
theme_few(背景色无,网格无,全坐标轴,分面标签无背景),
theme_base(背景色无,网格无,全坐标轴,分面标签无背景,字体稍大)

theme_classic (背景色无,网格无,半开坐标轴),
theme_cowplot (背景色无,网格无,半开坐标轴,字体稍大)

theme_void (背景色无,网格无,坐标轴无)
theme_solid (只有图,删除所有标签信息)

theme(line,rect,text,title,aspect.ratio,
      axis.title,axis.title.x,axis.title.x.top,axis.title.x.bottom,
      axis.title.y,axis.title.y.left,axis.title.y.right,
      axis.text,axis.text.x,axis.text.x.top,axis.text.x.bottom,
      axis.text.y,axis.text.y.left,axis.text.y.right,
      axis.ticks,axis.ticks.x,axis.ticks.x.top,axis.ticks.x.bottom,
      axis.ticks.y,axis.ticks.y.left,axis.ticks.y.right,
      axis.ticks.length,axis.ticks.length.x,axis.ticks.length.x.top,axis.ticks.length.x.bottom,
      axis.ticks.length.y,axis.ticks.length.y.left,axis.ticks.length.y.right,
      axis.line,axis.line.x,axis.line.x.top,axis.line.x.bottom,
      axis.line.y,axis.line.y.left,axis.line.y.right,

      legend.background,legend.margin,legend.spacing,
      legend.spacing.x,legend.spacing.y,
      legend.key,legend.key.size,legend.key.height,legend.key.width,
      legend.text,legend.text.align,legend.title,legend.title.align,
      legend.position,legend.direction,legend.justification,
      legend.box,legend.box.just,legend.box.margin,legend.box.background,legend.box.spacing,

      panel.background,panel.border,panel.spacing,panel.spacing.x,panel.spacing.y,
      panel.grid,panel.grid.major,panel.grid.minor,panel.grid.major.x,panel.grid.major.y,panel.grid.minor.x,panel.grid.minor.y,
      panel.ontop,plot.background,

      plot.title,plot.title.position,plot.subtitle,plot.caption,plot.caption.position,
      plot.tag,plot.tag.position,plot.margin,

      strip.background,strip.background.x,strip.background.y,strip.placement,
      strip.text,strip.text.x,strip.text.y,strip.switch.pad.grid,strip.switch.pad.wrap,
       ...,
      complete = FALSE,
      validate = TRUE
)

其他调整

颜色/透明度:
scale_color/fill_continuous
scale_color/fill_gradient
scale_color/fill_gradient2
scale_color/fill_gradientn
scale_color/fill_discrete
scale_color/fill_brewer
scale_color/fill_manual
scale_alpha_continuous
scale_alpha_discrete
scale_alpha_manual

大小/形状:
scale_size
scale_size_manual
scale_shape
scale_shape_manual

坐标轴:scale_x/y_continuous
scale_x/y_discrete,
scale_x/y_reverse
scale_x/y_log10
scale_x/y_sqrt
scales::percent
coord_cartesian(截断坐标轴)
coord_fixed
coord_flip
coord_trans
coord_polar

图例:
guide_colorbar
guide_legend
guides
      guides(color = "colorbar", size = "legend", shape = "legend")
  <==>guides(color = guide_colorbar(), size = guide_legend(),shape = guide_legend())
  <==>scale_color_continuous(guide = "colorbar") + scale_size_discrete(guide = "legend") + scale_shape(guide = "legend")
  <==>scale_color_continuous(guide = guide_colorbar()) + scale_size_discrete(guide = guide_legend()) + scale_shape(guide = guide_legend())

位置调整:
position_identity
position_dodge
position_jitter
position_jitterdodge
position_stack
position_fill

分面:
facet_grid
facet_wrap
上一篇下一篇

猜你喜欢

热点阅读