ggstatsplot繪圖|統(tǒng)計+可視化努释,學術(shù)科研神器

本文首發(fā)于“生信補給站”公眾號苫耸,https://mp.weixin.qq.com/s/zdSit97SOEpbnR18ARzixw

更多關(guān)于R語言夹姥,ggplot2繪圖杉武,生信分析的內(nèi)容,敬請關(guān)注小號辙售。

ggstatsplotggplot2包的擴展包轻抱,可以同時輸出美觀的圖片和統(tǒng)計分析結(jié)果,對于經(jīng)常做統(tǒng)計分析或者生信人來說非常有用旦部。

一 準備數(shù)據(jù)

gapminder 數(shù)據(jù)集包含1952到2007年間(5年間隔)的142個國家的life expectancy, GDP per capita, 和 population信息

#載入繪圖R包
library(ggstatsplot)
#載入gapminder 數(shù)據(jù)集

library(gapminder)
head(gapminder)
image.png

ggstatsplot-R包含有很多繪圖函數(shù)(文末會給出)祈搜,本文僅展示ggbetweenstats函數(shù)使用方法。

二 ggbetweenstats 繪圖

1 基本繪圖展示

顯示2007年每個continent的預期壽命分布情況士八,并統(tǒng)計一下不同大陸之間平均預期壽命的是否有差異容燕?差異是否顯著?

#設置種子方便復現(xiàn)
set.seed(123)
# Oceania數(shù)據(jù)太少婚度,去掉后分析
ggstatsplot::ggbetweenstats(
  data = dplyr::filter(
    .data = gapminder::gapminder,
    year == 2007, continent != "Oceania"
  ),
  x = continent,
  y = lifeExp,
  nboot = 10,
  messages = FALSE
)
img

可以看到圖中展示出了2007年每個continent的預期壽命分布的箱線圖蘸秘,點圖和小提琴圖,均值蝗茁,樣本數(shù)醋虏;并且圖形最上方給出了模型的一些統(tǒng)計量信息(整體)。

統(tǒng)計信息意義如下圖所示:

img

注:該函數(shù)根據(jù)分組變量中的個數(shù)自動決定是選擇獨立樣本t檢驗(2組)還是單因素方差分析(3組或更多組)

2 添加統(tǒng)計值

上方給出了整體的檢驗P值评甜,下面兩兩之間比較灰粮,并添加檢驗統(tǒng)計量

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
)

img

3 圖形美化

添加標題和說明,x軸和y軸標簽忍坷,標記粘舟,離群值,更改主題以及調(diào)色板佩研。

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)
  )

img

三 其他繪圖函數(shù)

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生存分析結(jié)果可視化

Forest plot(森林圖) | Cox生存分析可視化

maftools|TCGA腫瘤突變數(shù)據(jù)的匯總,分析和可視化

maftools | 從頭開始繪制發(fā)表級oncoplot(瀑布圖)

ggalluvial|炫酷裳恚基圖(Sankey)晰骑,你也可以秀

ggplot2|詳解八大基本繪圖要素

ggplot2|ggpubr進行“paper”組圖合并

pheatmap|暴雨暫歇,“熱圖”來襲0硇颉K队摺!

ggplot2-plotly|讓你的火山圖“活”過來

ggplot2| 繪制KEGG氣泡圖

ggplot2|繪制GO富集柱形圖

繪圖系列|R-corrplot相關(guān)圖

繪圖系列|R-VennDiagram包繪制韋恩圖

R|clusterProfiler-富集分析

【覺得不錯骤公,右下角點個“在看”抚官,期待您的轉(zhuǎn)發(fā),謝謝阶捆!】

img
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末凌节,一起剝皮案震驚了整個濱河市钦听,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌倍奢,老刑警劉巖朴上,帶你破解...
    沈念sama閱讀 218,682評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異卒煞,居然都是意外死亡痪宰,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,277評論 3 395
  • 文/潘曉璐 我一進店門跷坝,熙熙樓的掌柜王于貴愁眉苦臉地迎上來酵镜,“玉大人,你說我怎么就攤上這事柴钻』淳拢” “怎么了?”我有些...
    開封第一講書人閱讀 165,083評論 0 355
  • 文/不壞的土叔 我叫張陵贴届,是天一觀的道長靠粪。 經(jīng)常有香客問我,道長毫蚓,這世上最難降的妖魔是什么占键? 我笑而不...
    開封第一講書人閱讀 58,763評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮元潘,結(jié)果婚禮上畔乙,老公的妹妹穿的比我還像新娘。我一直安慰自己翩概,他們只是感情好牲距,可當我...
    茶點故事閱讀 67,785評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著钥庇,像睡著了一般牍鞠。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上评姨,一...
    開封第一講書人閱讀 51,624評論 1 305
  • 那天难述,我揣著相機與錄音,去河邊找鬼吐句。 笑死胁后,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的嗦枢。 我是一名探鬼主播攀芯,決...
    沈念sama閱讀 40,358評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼净宵!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,261評論 0 276
  • 序言:老撾萬榮一對情侶失蹤择葡,失蹤者是張志新(化名)和其女友劉穎紧武,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體敏储,經(jīng)...
    沈念sama閱讀 45,722評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡阻星,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了已添。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片妥箕。...
    茶點故事閱讀 40,030評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖更舞,靈堂內(nèi)的尸體忽然破棺而出畦幢,到底是詐尸還是另有隱情,我是刑警寧澤缆蝉,帶...
    沈念sama閱讀 35,737評論 5 346
  • 正文 年R本政府宣布宇葱,位于F島的核電站,受9級特大地震影響刊头,放射性物質(zhì)發(fā)生泄漏黍瞧。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,360評論 3 330
  • 文/蒙蒙 一原杂、第九天 我趴在偏房一處隱蔽的房頂上張望印颤。 院中可真熱鬧,春花似錦穿肄、人聲如沸年局。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,941評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽某宪。三九已至,卻和暖如春锐朴,著一層夾襖步出監(jiān)牢的瞬間兴喂,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,057評論 1 270
  • 我被黑心中介騙來泰國打工焚志, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留衣迷,地道東北人。 一個月前我還...
    沈念sama閱讀 48,237評論 3 371
  • 正文 我出身青樓酱酬,卻偏偏與公主長得像壶谒,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子膳沽,可洞房花燭夜當晚...
    茶點故事閱讀 44,976評論 2 355

推薦閱讀更多精彩內(nèi)容