极大补充ggplot2的统计分析能力
本次分享ggplot2的强力扩展ggstatsplot,它的核心优势在于将统计检验结果(如p值、效应量)无缝集成到ggplot2图形中,实现数据可视化与统计分析的同步呈现。
library(ggstatsplot)
library(ggplot2)
library(ggthemes)
options(repr.plot.width = 8, repr.plot.height = 6, repr.plot.res = 300)
ggstatsplot::ggbetweenstats(
data = iris_data, #1.4.8 iris数据集
x = species,
y = sepal_length,
gtheme = ggthemes::theme_fivethirtyeight()
)
1 APA 格式统计结果展示
统计结果展示参考了APA 格式,每个字段含义如下,
2展示数据组间P value统计指标 3 其它,如均值等描述性统计指标
当然,可以使用grouped_ggbetweenstats实现多子图展示
set.seed(123)
options(repr.plot.width = 12, repr.plot.height = 8, repr.plot.res = 300)
grouped_ggbetweenstats( #多子图
data = dplyr::filter(movies_long, genre %in% c("Action", "Comedy")),
x = mpaa,
y = length,
grouping.var = genre,
ggsignif.args = list(textsize = 4, tip_length = 0.01),
p.adjust.method = "bonferroni",
gtheme = ggthemes::theme_fivethirtyeight(),
plotgrid.args = list(nrow = 1)
)
也可以ggwithinstats实现这种手拉手的统计图,
options(repr.plot.width = 8, repr.plot.height = 6, repr.plot.res = 300)
Sys.setlocale("LC_ALL", "C")
set.seed(123)
library(WRS2)
# plot
ggstatsplot::ggwithinstats( #手拉手
data = WineTasting,
x = Wine,
y = Taste,
ggtheme = ggthemes::theme_fivethirtyeight(),
ggstatsplot.layer = FALSE,
messages = FALSE,
ggsignif.args = list(textsize = 3, tip_length = 0.01),
)
当然, ggstatsplot的能力远不至此,例如,
-推荐阅读-
👉matplotlib教程:20w字+数百张图形+1W行代码+详细代码注释+学习交流群
👉seaborn教程:12.3万字+500多张图形+8000行代码
如何加入学习?
👇(请备注:299)