原文:https://indrajeetpatil.github.io/ggstatsplot/index.html
ggstatsplot是gglot2的拓展包,可以为统计测试添加详细的图形信息。ggstatsplot的设计理念是把统计和绘图合二为一,即作图又添加统计细节,让数据挖掘更简洁快速。
此包支持的统计绘图函数和图形
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 |
ggscatterstats |
scatterplots | for correlation between two variables |
ggcorrmat |
correlation matrices | for correlations between multiple variables |
ggpiestats |
pie charts | for categorical data |
ggbarstats |
bar charts | for categorical data |
ggcoefstats |
dot-and-whisker plots | for regression models and meta-analysis |
统计分析类型汇总
Functions | Description | Parametric | Non-parametric | Robust | Bayesian |
---|---|---|---|---|---|
ggbetweenstats |
Between group/condition comparisons | Yes | Yes | Yes | Yes |
ggwithinstats |
Within group/condition comparisons | Yes | Yes | Yes | Yes |
gghistostats , ggdotplotstats
|
Distribution of a numeric variable | Yes | Yes | Yes | Yes |
ggcorrmat |
Correlation matrix | Yes | Yes | Yes | Yes |
ggscatterstats |
Correlation between two variables | Yes | Yes | Yes | Yes |
ggpiestats , ggbarstats
|
Association between categorical variables | Yes | NA |
NA |
Yes |
ggpiestats , ggbarstats
|
Equal proportions for categorical variable levels | Yes | NA |
NA |
Yes |
ggcoefstats |
Regression model coefficients | Yes | Yes | Yes | Yes |
ggcoefstats |
Random-effects meta-analysis | Yes | NA |
Yes | Yes |
贝叶斯分析
Analysis | Hypothesis testing | Estimation |
---|---|---|
(one/two-sample) t-test | Yes | Yes |
one-way ANOVA | Yes | Yes |
correlation | Yes | Yes |
(one/two-way) contingency table | Yes | Yes |
random-effects meta-analysis | Yes | Yes |
统计报告举例
Yuen’s test for trimmed means (robust t-test):
安装
install.packages("ggstatsplot")
加载绘图
library(ggstatsplot)
ggstatsplot::ggbetweenstats(
data = iris,
x = Species,
y = Sepal.Length,
title = "Distribution of sepal length across Iris species"
)
library(ggplot2)
ggstatsplot::ggbetweenstats(
data = ToothGrowth,
x = supp,
y = len,
type = "r", # robust statistics
k = 3, # number of decimal places for statistical results
xlab = "Supplement type", # label for the x-axis variable
ylab = "Tooth length", # label for the y-axis variable
title = "The Effect of Vitamin C on Tooth Growth", # title text for the plot
ggtheme = ggthemes::theme_fivethirtyeight(), # choosing a different theme
ggstatsplot.layer = FALSE, # turn off `ggstatsplot` theme layer
package = "wesanderson", # package from which color palette is to be taken
palette = "Darjeeling1" # choosing a different color palette
)
ggstatsplot::grouped_ggbetweenstats(
data = dplyr::filter(
.data = ggstatsplot::movies_long,
genre %in% c("Action", "Action Comedy", "Action Drama", "Comedy")
),
x = mpaa,
y = length,
grouping.var = genre, # grouping variable
outlier.tagging = TRUE, # whether outliers need to be tagged
outlier.label = title, # variable to be used for tagging outliers
outlier.coef = 2,
ggsignif.args = list(textsize = 4, tip_length = 0.01),
p.adjust.method = "bonferroni", # method for adjusting p-values for multiple comparisons
# adding new components to `ggstatsplot` default
ggplot.component = list(ggplot2::scale_y_continuous(sec.axis = ggplot2::dup_axis())),
title.prefix = "Movie genre",
caption = substitute(paste(italic("Source"), ": IMDb (Internet Movie Database)")),
palette = "default_jama",
package = "ggsci",
plotgrid.args = list(nrow = 2),
annotation.args = list(title = "Differences in movie length by mpaa ratings for different genres")
)
还有很多例子,大家可以自由探索!!!