【R】ggstatsplot
2020年11月28日
1. はじめに
ggstatsplotは、ggplot2のグラフをよりinformation-tichにしてくれるパッケージです。通常は、データ処理->データ表示の2ステップで実施されますが、これを1ステップで実施できるパッケージでもあります。
2. インストール
CRANからインストールできます。
install.packages("ggstatsplot")
3. 使ってみる
使える機能は次のとおりです。ここでは、一部を紹介します。
| 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 and meta-analysis |
3.1 ggbetweenstats
ggstatsplot::ggbetweenstats( data = iris, x = Species, y = Sepal.Width, title = "Distribution of sepal width across Iris species" )

3.2 ggscatterstats
ggstatsplot::ggscatterstats( data = diamonds, x = carat, y = price, xlab = "Carat", ylab = "Price", title = "Diamond price" )

3.3 ggpiestats
ggstatsplot::ggpiestats( data = diamonds, x = color, y = cut, title = "Dataset: Diamonds", legend.title = "Color" )

3.4 grouped_gghistostats
set.seed(123)
ggstatsplot::grouped_gghistostats(
data = dplyr::filter(
.data = ggstatsplot::movies_long,
genre %in% c("Action", "Action Comedy", "Action Drama", "Comedy")
),
x = budget,
xlab = "Movies budget (in million US$)",
type = "robust", # use robust location measure
grouping.var = genre, # grouping variable
normal.curve = TRUE, # superimpose a normal distribution curve
normal.curve.args = list(color = "red", size = 1),
title.prefix = "Movie genre",
ggtheme = ggthemes::theme_tufte(),
ggplot.component = list( # modify the defaults from `ggstatsplot` for each plot
ggplot2::scale_x_continuous(breaks = seq(0, 200, 50), limits = (c(0, 200)))
),
plotgrid.args = list(nrow = 2),
title.text = "Movies budgets for different genres"
)

4. さいごに
これ、すごいですね。ただただ驚愕!