24
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

aesの一覧表を見たい

Last updated at Posted at 2015-09-30

Q

aesで指定できるパラメータはグラフ(geom)の種類によって違いますが、どこかに一覧表はありますか? 対応するドキュメントを?geom_XXXで見れば書いてありますが、まとめて一覧で見たいんです。

A

残念ながら、ドキュメントに一覧表は用意されていませんが、それぞれのgeomに指定できるパラメータとその初期値は以下のようになっています。(yesとなっているものは、使えるけど初期値が設定されていないパラメータ、requiredは指定が必須のパラメータです)

geom colour size linetype alpha fill x y weight ymin ymax minor params
Abline black 0.5 1 yes -- -- -- -- -- -- slope=required, intercept=required
AnnotationMap yes 0.5 1 yes grey20 -- -- -- -- --
Area yes 0.5 1 yes grey20 required required -- -- --
Bar yes 0.5 1 yes grey20 required -- -- -- --
Blank -- -- -- -- -- -- -- -- -- --
Boxplot grey20 0.5 solid yes white required -- 1 required required shape=19, outlier.colour=black, outlier.shape=19, outlier.size=1.5, outlier.stroke=0.5, lower=required, upper=required, middle=required
Contour #3366FF 0.5 1 yes -- required required 1 -- --
Crossbar black 0.5 1 yes yes required required -- required required
Curve black 0.5 1 yes -- required required -- -- -- xend=required, yend=required
CustomAnn -- -- -- -- -- -- -- -- -Inf Inf xmin=-Inf, xmax=Inf
Density black 0.5 1 yes yes required required 1 -- --
Density2d #3366FF 0.5 1 yes -- required required -- -- --
Dotplot black -- -- yes black required required -- -- --
Errorbar black 0.5 1 yes -- required -- -- required required width=0.5
Errorbarh black 0.5 1 yes -- required required -- -- -- xmin=required, xmax=required, height=0.5
Hex yes 0.5 -- yes grey50 required required -- -- --
Hline black 0.5 1 yes -- -- -- -- -- -- yintercept=required
Label black 3.88 -- yes white required required -- -- -- angle=0, hjust=0.5, vjust=0.5, family=, fontface=1, lineheight=1.2, label=required
Line black 0.5 1 yes -- required required -- -- --
Linerange black 0.5 1 yes -- required -- -- required required
Logticks black 0.5 1 1 -- -- -- -- -- --
Map yes 0.5 1 yes grey20 -- -- -- -- -- map_id=required
Path black 0.5 1 yes -- required required -- -- --
Point black 1.5 -- yes yes required required -- -- -- shape=19, stroke=0.5
Pointrange black 0.5 1 yes yes required required -- required required shape=19, stroke=1
Polygon yes 0.5 1 yes grey20 required required -- -- --
Quantile #3366FF 0.5 1 yes -- required required 1 -- --
Raster -- -- -- yes grey20 required required -- -- --
RasterAnn -- -- -- yes grey20 required required -- -- --
Rect yes 0.5 1 yes grey20 -- -- -- required required xmin=required, xmax=required
Ribbon yes 0.5 1 yes grey20 required -- -- required required
Rug black 0.5 1 yes -- -- -- -- -- --
Segment black 0.5 1 yes -- required required -- -- -- xend=required, yend=required
Smooth #3366FF 1 1 0.4 grey60 required required 1 -- --
Spoke black 0.5 1 yes -- required required -- -- -- angle=required, radius=required
Step black 0.5 1 yes -- required required -- -- --
Text black 3.88 -- yes -- required required -- -- -- angle=0, hjust=0.5, vjust=0.5, family=, fontface=1, lineheight=1.2, label=required
Tile yes 0.1 1 yes grey20 required required -- -- --
Violin grey20 0.5 solid yes white required required 1 -- --
Vline black 0.5 1 yes -- -- -- -- -- -- xintercept=required

これを生成するコードはこんな感じです。

library(dplyr)
library(purrr)
library(ggplot2)
e      <- asNamespace('ggplot2')
Geoms  <- grep("^Geom.+", ls(e), value = TRUE)

geoms  <- 
  Geoms %>%
  map(get, envir = e)

f <- function(geom) {
  aes_default <- geom$default_aes %>%
    map_if(is.na,  ~ ("yes")) %>%
    map_if(~ . == "NA", ~ ("yes")) %>%
    map(as.character) %>%
    as.list
  
  aes_required <- setNames(rep("required", length(geom$required_aes)),
                           geom$required_aes )
  
  c(geom = sub("Geom", "", class(geom)[1]),
    aes_default,
    aes_required)
}

aeses <- geoms %>%
  map(f) %>%
  bind_rows

# NAの数で分割
is_few_na <- function(col) sum(is.na(col)) < 35
aeses_major <- keep(aeses, is_few_na)
aeses_minor <- discard(aeses, is_few_na)

aeses_minor <-
  aeses_minor %>%
  by_row(. %>%
           discard(is.na) %>%
           paste(names(.), ., sep = "=", collapse = ", "),
         .labels = FALSE) %>%
  rename(`minor params` = .out)

result <- bind_cols(aeses_major, aeses_minor)

# 見やすいようにNAは--で表示する
result[is.na(result)] <- '--'

# Markdown用のテーブルを出力
knitr::kable(result)

参考

この記事は、以下のstackoverflowの内容を参考に書き起こしました:

24
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?