【R】ggstatsplot
2020年12月29日
1. はじめに
ggstatsplot
は,data explanationとすぐに出力できるチャート/プロットを描画してくれるパッケージです。
2. インストール
CRANからインストールします。
install.packages("ggstatsplot")
3. つかってみる
米Environmental Protection Agency(EPA)がhttps://fueleconomy.gov/で出しているfuel economy dataのデータを見ています。
library(tidyverse) glimpse(x = ggplot2::mpg)
Rows: 234
Columns: 11
$ manufacturer <chr> "audi", "audi", "audi", "audi", "audi", "audi", "audi", "audi",...
$ model <chr> "a4", "a4", "a4", "a4", "a4", "a4", "a4", "a4 quattro", "a4 qua...
$ displ <dbl> 1.8, 1.8, 2.0, 2.0, 2.8, 2.8, 3.1, 1.8, 1.8, 2.0, 2.0, 2.8, 2.8...
$ year <int> 1999, 1999, 2008, 2008, 1999, 1999, 2008, 1999, 1999, 2008, 200...
$ cyl <int> 4, 4, 4, 4, 6, 6, 6, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8, ...
$ trans <chr> "auto(l5)", "manual(m5)", "manual(m6)", "auto(av)", "auto(l5)",...
$ drv <chr> "f", "f", "f", "f", "f", "f", "f", "4", "4", "4", "4", "4", "4"...
$ cty <int> 18, 21, 20, 21, 16, 18, 18, 18, 16, 20, 19, 15, 17, 17, 15, 15,...
$ hwy <int> 29, 29, 31, 30, 26, 26, 27, 26, 25, 28, 27, 25, 25, 25, 25, 24,...
$ fl <chr> "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p"...
$ class <chr> "compact", "compact", "compact", "compact", "compact", "compact...
> glimpse(x = ggplot2::mpg)
Rows: 234
Columns: 11
$ manufacturer <chr> "audi", "audi", "audi", "audi", "audi", "audi", "audi", "audi",...
$ model <chr> "a4", "a4", "a4", "a4", "a4", "a4", "a4", "a4 quattro", "a4 qua...
$ displ <dbl> 1.8, 1.8, 2.0, 2.0, 2.8, 2.8, 3.1, 1.8, 1.8, 2.0, 2.0, 2.8, 2.8...
$ year <int> 1999, 1999, 2008, 2008, 1999, 1999, 2008, 1999, 1999, 2008, 200...
$ cyl <int> 4, 4, 4, 4, 6, 6, 6, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8, ...
$ trans <chr> "auto(l5)", "manual(m5)", "manual(m6)", "auto(av)", "auto(l5)",...
$ drv <chr> "f", "f", "f", "f", "f", "f", "f", "4", "4", "4", "4", "4", "4"...
$ cty <int> 18, 21, 20, 21, 16, 18, 18, 18, 16, 20, 19, 15, 17, 17, 15, 15,...
$ hwy <int> 29, 29, 31, 30, 26, 26, 27, 26, 25, 28, 27, 25, 25, 25, 25, 24,...
$ fl <chr> "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p"...
$ class <chr> "compact", "compact", "compact", "compact", "compact", "compact...
こんな例も。
df <- filter(.data = ggplot2::mpg, cyl %in% c("4", "6")) grouped_ggdotplotstats( data = df, x = cty, y = manufacturer, xlab = "city miles per gallon", ylab = "car manufacturer", grouping.var = cyl, type = "bayes", test.value = 15.5, title.prefix = "cylinder count", point.args = list( color = "red", size = 5, shape = 13 ), test.value.line = TRUE, ggtheme = ggthemes::theme_fivethirtyeight(), title.text = "Fuel economy data", plotgrid.args = list(nrow = 2) )
4. さいごに
まだ、使い方がすべては分かりませんが・・・。便利そうです。