本文首发于“生信补给站”公众号,https://mp.weixin.qq.com/s/zdSit97SOEpbnR18ARzixw

更多关于R语言,ggplot2绘图,生信分析的内容,敬请关注小号。

ggstatsplotggplot2包的扩展包,可以同时输出美观的图片和统计分析结果,对于经常做统计分析或者生信人来说非常有用。

一 准备数据

gapminder 数据集包含1952到2007年间(5年间隔)的142个国家的life expectancy, GDP per capita, 和 population信息

#载入绘图R包
library(ggstatsplot)
#载入gapminder 数据集

library(gapminder)
head(gapminder)

ggstatsplot-R包含有很多绘图函数(文末会给出),本文仅展示ggbetweenstats函数使用方法。

二 ggbetweenstats 绘图

1 基本绘图展示

显示2007年每个continent的预期寿命分布情况,并统计一下不同大陆之间平均预期寿命的是否有差异?差异是否显著?

#设置种子方便复现
set.seed(123)
# Oceania数据太少,去掉后分析
ggstatsplot::ggbetweenstats(
 data = dplyr::filter(
   .data = gapminder::gapminder,
   year == 2007, continent != "Oceania"
),
 x = continent,
 y = lifeExp,
 nboot = 10,
 messages = FALSE
)

可以看到图中展示出了2007年每个continent的预期寿命分布的箱线图,点图和小提琴图,均值,样本数;并且图形最上方给出了模型的一些统计量信息(整体)。

统计信息意义如下图所示:

注:该函数根据分组变量中的个数自动决定是选择独立样本t检验(2组)还是单因素方差分析(3组或更多组)

2 添加统计值

上方给出了整体的检验P值,下面两两之间比较,并添加检验统计量

set.seed(123)
ggstatsplot::ggbetweenstats(
 data = dplyr::filter(
   .data = gapminder::gapminder,year == 2007, continent != "Oceania"),
 x = continent,y = lifeExp,
 nboot = 10,
 messages = FALSE,
 effsize.type = "unbiased", # type of effect size (unbiased = omega)
 partial = FALSE, # partial omega or omega?
 pairwise.comparisons = TRUE, # display results from pairwise comparisons
 pairwise.display = "significant", # display only significant pairwise comparisons
 pairwise.annotation = "p.value", # annotate the pairwise comparisons using p-values
 p.adjust.method = "fdr", # adjust p-values for multiple tests using this method
)

3 图形美化

#添加标题和说明,x轴和y轴标签,标记,离群值,更改主题以及调色板。

set.seed(123)
# plot
gapminder %>% # dataframe to use
 ggstatsplot::ggbetweenstats(
   data = dplyr::filter(.data = ., year == 2007, continent != "Oceania"),
   x = continent, # grouping/independent variable
   y = lifeExp, # dependent variables
   xlab = "Continent", # label for the x-axis
   ylab = "Life expectancy", # label for the y-axis
   plot.type = "boxviolin", # type of plot ,"box", "violin", or "boxviolin"
   type = "parametric", # type of statistical test , p (parametric), np ( nonparametric), r(robust), bf (Bayes Factor).
   effsize.type = "biased", # type of effect size
   nboot = 10, # number of bootstrap samples used
   bf.message = TRUE, # display bayes factor in favor of null hypothesis
   outlier.tagging = TRUE, # whether outliers should be flagged
   outlier.coef = 1.5, # coefficient for Tukey's rule
   outlier.label = country, # label to attach to outlier values
   outlier.label.color = "red", # outlier point label color
   mean.plotting = TRUE, # whether the mean is to be displayed
   mean.color = "darkblue", # color for mean
   messages = FALSE, # turn off messages
   ggtheme = ggplot2::theme_gray(), # a different theme
   package = "yarrr", # package from which color palette is to be taken
   palette = "info2", # choosing a different color palette
   title = "Comparison of life expectancy across continents (Year: 2007)",
   caption = "Source: Gapminder Foundation"
) + # modifying the plot further
 ggplot2::scale_y_continuous(
   limits = c(35, 85),
   breaks = seq(from = 35, to = 85, by = 5)
)

三 其他绘图函数

Function Plot Description
ggbetweenstats violin plots for comparisons between groups/conditions
ggwithinstats violin plots for comparisons within groups/conditions
gghistostats histograms for distribution about numeric variable
ggdotplotstats dot plots/charts for distribution about labeled numeric variable
ggpiestats pie charts for categorical data
ggbarstats bar charts for categorical data
ggscatterstats scatterplots for correlations between two variables
ggcorrmat correlation matrices for correlations between multiple variables
ggcoefstats dot-and-whisker plots for regression models

四 更多请参照官方文档

https://indrajeetpatil.github.io/ggstatsplot/index.html

◆ ◆ ◆ ◆ ◆

R|生存分析(1):生存分析介绍以及绘制KM曲线

Nomogram(诺莫图) | Logistic、Cox生存分析结果可视化

Forest plot(森林图) | Cox生存分析可视化

maftools|TCGA肿瘤突变数据的汇总,分析和可视化

maftools | 从头开始绘制发表级oncoplot(瀑布图)

ggalluvial|炫酷桑基图(Sankey),你也可以秀

ggplot2|详解八大基本绘图要素

ggplot2|ggpubr进行“paper”组图合并

pheatmap|暴雨暂歇,“热图”来袭!!!

ggplot2-plotly|让你的火山图“活”过来

ggplot2| 绘制KEGG气泡图

ggplot2|绘制GO富集柱形图

绘图系列|R-corrplot相关图

绘图系列|R-VennDiagram包绘制韦恩图

R|clusterProfiler-富集分析

【觉得不错,右下角点个“在看”,期待您的转发,谢谢!】

ggstatsplot绘图|统计+可视化,学术科研神器的更多相关文章

  1. Python 数据分析(一) 本实验将学习 pandas 基础,数据加载、存储与文件格式,数据规整化,绘图和可视化的知识

    第1节 pandas 回顾 第2节 读写文本格式的数据 第3节 使用 HTML 和 Web API 第4节 使用数据库 第5节 合并数据集 第6节 重塑和轴向旋转 第7节 数据转换 第8节 字符串操作 ...

  2. python金融与量化分析------Matplotlib(绘图和可视化)

    -----------------------------------------------------------Matplotlib:绘图和可视化------------------------ ...

  3. Python之绘图和可视化

    Python之绘图和可视化 1. 启用matplotlib 最常用的Pylab模式的IPython(IPython --pylab) 2. matplotlib的图像都位于Figure对象中. 可以使 ...

  4. Matplotlib:绘图和可视化

    Matplotlib:绘图和可视化 简介 简单绘制线形图 plot函数 支持图类型 保存图表 一 .简介 Matplotlib是一个强大的Python绘图和数据可视化的工具包.数据可视化也是我们数据分 ...

  5. Python绘图与可视化

    Python有很多可视化工具,本篇只介绍Matplotlib. Matplotlib是一种2D的绘图库,它可以支持硬拷贝和跨系统的交互,它可以在Python脚本.IPython的交互环境下.Web应用 ...

  6. R语言 ETL+统计+可视化

    这篇文章...还是看文章吧 导入QQ群信息,进行ETL,将其规范化 计算哪些QQ发言较多 计算一天中哪些时段发言较多 计算统计内所有天的日发言量 setwd("C:/Users/liyi/D ...

  7. 《利用python进行数据分析》读书笔记--第八章 绘图和可视化

    http://www.cnblogs.com/batteryhp/p/5025772.html python有许多可视化工具,本书主要讲解matplotlib.matplotlib是用于创建出版质量图 ...

  8. JFreeChart与AJAX+JSON+ECharts两种处理方式生成热词统计可视化图表

    本篇的思想:对HDFS获取的数据进行两种不同的可视化图表处理方式.第一种JFreeChar可视化处理生成图片文件查看.第二种AJAX+JSON+ECharts实现可视化图表,并呈现于浏览器上.   对 ...

  9. matlab绘图与可视化

    1.设置图形对象属性值 set(h,'属性名称','属性值') >> subplot(,,); h1=line([ ],[ ]); text(,0.5,'unchange'); subpl ...

随机推荐

  1. 苹果系统IOS第三方管理工具——imazing 优秀

    iMazing 是一款 Windows.macOS 平台的 iPhone.iPad 管理工具,可以进行文件.音乐.视频传输,备份与还原数据,并且可以管理已安装应用,比如重新安装那些已下架的应用,是「史 ...

  2. el-table合并行并自定义某一列或几列

    在el-table的官方组件中并没有看到具体的合并行或者列及自定义表格内容,于是就自己写了一个效果如下所示. 这种对左侧内容要求比较高,要求行合并,并要自定义一些内容.下面说一下具体方法及代码写法. ...

  3. Java基本数据类型转换及运算符

    上次我们说到完了Java中的基本数据类型,今天我们来说说Java中的基本数据类型转换和Java中的运算符 基本数据类型转换 java中可以从任意基本数据类型转型到外的基本数据类型 注意:(boolea ...

  4. 接口测试时数据格式是json,如何将响应内容转换为字典解析

    import requests url = 'http://127.0.0.1:5050/index' def apiTestPost(url): datas = { 'a':'cisco3', 'b ...

  5. 阿里云搭建nginx + uWSGI 实现 django 项目

    系统版本 CentOS/7 64位 1.安装使用python3 创建python3目录 sudo mkdir /usr/local/python3 进入python3目录 cd /usr/local/ ...

  6. Springboot2.1.x配置Activiti7单独数据源问题

    Springboot2.1.x配置Activiti7单独数据源问题 简介 最近基于最新的Activiti7配置了SpringBoot2. 简单上手使用了一番.发现市面上解决Activiti7的教程很少 ...

  7. 安装centos8

    一.     镜像下载 国内源下载镜像:(推荐) http://mirrors.aliyun.com/centos/8.0.1905/isos/x86_64/CentOS-8-x86_64-1905- ...

  8. rt.jar包添加源文件只需要关联到已安装对应jdk目录下source.zip源码文件即可

    项目中配置的JRE System Libriry下的rt.jar包,需要关联源文件时候,只需要点击“Attach Source...“按钮,选择"External File..." ...

  9. 【IT技术概念】WebAPI与传统的WebService有哪些不同?

    在.net平台下,有大量的技术让你创建一个HTTP服务,像Web Service,WCF,现在又出了Web API.在.net平台下,你有很多的选择来构建一个HTTP Services.我分享一下我对 ...

  10. ActiveMQ学习总结------入门篇01

    注:*这篇博文文章主要介绍ActiveMQ是什么原理性的内容和如何安装和简易操作 一. ActiveMQ  简介 1 ActiveMQ是什么呢?看起来好碉堡的东西哇! ActiveMQ 是 Apach ...