有ggplot2的美学表或目录吗? [英] Is there a table or catalog of aesthetics for ggplot2?

查看:149
本文介绍了有ggplot2的美学表或目录吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ggplot2的新手,一直在努力寻找美学的全面清单。我认为我理解他们的目的,但很难知道哪些可以用于各种情况(主要是几何?)。哈德利的网站偶尔列出了各个geoms页面上的可用美学,而R doc偶尔(尽管更少)也是这样做。我甚至找到了两个不太匹配的geom。

I am new to ggplot2 and have been trying to find a comprehensive list of aesthetics. I think I understand their purpose but it is hard to know which can be used in various situations (mostly geoms?). Hadley's website occasionally lists available aesthetics on pages for individual geoms and the R doc's occasionally (though more rarely) do the same. I even found a geom for which the two do not quite match.

我搜索了这里的评论以获得答案,甚至购买了这本书!唉,没有帮助。

I searched through the comments here for an answer and even bought the book! Alas, no help.

我认为拥有一张所有列在一个维度中的美学表格以及列出的所有几何图形(以及其他物体)另一个。

I think it would be fantastic to have a table with all the aesthetics listed in one dimension and all the geoms (and other objects?) listed in another.

有没有人知道这样的事情?

Does anyone know of such a thing?

有没有简单的方法(命令)所有可应用于对象的美学?

Is there a simple way (command) in R to list all the aesthetics that can be applied to an object?

以下是表格的开始方式:

Here's how a table might start:

List           x       y       fill      size    colour   linetype . . .
geom_point    Yes     Yes      Yes       Yes      Yes        No
geom_abline   Yes     Yes      No        Yes      Yes       Yes
.
.
.

美学定义/参数目录也是非常有用的参考。

A catalog of aesthetic definitions/parameters would be a very helpful reference as well.

推荐答案

以下是每个geom的 default_aes

Below is the default_aes for each geom,

            colour size linetype alpha   fill weight shape width height angle hjust vjust family fontface lineheight
abline       black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
area           yes  0.5        1   yes grey20     --    --    --     --    --    --    --     --       --         --
bar            yes  0.5        1   yes grey20      1    --    --     --    --    --    --     --       --         --
bin2d          yes  0.5        1   yes grey60      1    --    --     --    --    --    --     --       --         --
boxplot     grey20  0.5    solid   yes  white      1    16    --     --    --    --    --     --       --         --
contour    #3366FF  0.5        1   yes     --      1    --    --     --    --    --    --     --       --         --
crossbar     black  0.5        1   yes    yes     --    --    --     --    --    --    --     --       --         --
density      black  0.5        1   yes    yes      1    --    --     --    --    --    --     --       --         --
density2d  #3366FF  0.5        1   yes     --      1    --    --     --    --    --    --     --       --         --
errorbar     black  0.5        1   yes     --     --    --   0.5     --    --    --    --     --       --         --
errorbarh    black  0.5        1   yes     --     --    --    --    0.5    --    --    --     --       --         --
freqpoly     black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
hex            yes  0.5       --   yes grey50     --    --    --     --    --    --    --     --       --         --
hline        black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
linerange    black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
path         black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
point        black    2       --   yes    yes     --    16    --     --    --    --    --     --       --         --
pointrange   black  0.5        1   yes    yes     --    16    --     --    --    --    --     --       --         --
polygon         NA  0.5        1   yes grey20     --    --    --     --    --    --    --     --       --         --
quantile   #3366FF  0.5        1   yes     --      1    --    --     --    --    --    --     --       --         --
raster          --   --       --   yes grey20     --    --    --     --    --    --    --     --       --         --
rect           yes  0.5        1   yes grey20     --    --    --     --    --    --    --     --       --         --
ribbon         yes  0.5        1   yes grey20     --    --    --     --    --    --    --     --       --         --
rug          black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
segment      black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
smooth     #3366FF  0.5        1   0.4 grey60      1    --    --     --    --    --    --     --       --         --
step         black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
text         black    5       --   yes     --     --    --    --     --     0   0.5   0.5               1        1.2
tile           yes  0.1        1   yes grey20     --    --    --     --    --    --    --     --       --         --
violin      grey20  0.5    solid   yes  white      1    --    --     --    --    --    --     --       --         --
vline        black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --

以及我用来破解这个的丑陋代码,

and the ugly code I used to hack this,

find_aes <- function(geom="point"){

  tryCatch({
  Geom <- getFromNamespace(paste("Geom", ggplot2:::firstUpper(geom), sep=""),
                           "ggplot2")

  tmp <- unclass(Geom$default_aes)
  tmp[is.na(tmp)] <- "yes"
  data.frame(tmp, stringsAsFactors=FALSE)
  }, error = function(e) {})
}

funs <- grep("^geom_", ls("package:ggplot2"),val=T)

geoms <- gsub("^geom_", "", funs)

all <- lapply(geoms, find_aes)
names(all) <- geoms
relevant <- sapply(all, function(x) !is.null(x) && nrow(x) > 0)
library(plyr)
results = do.call("rbind.fill",all)
rownames(results) <- names(relevant[relevant])
results[is.na(results)] <- "--"

options(width=9999)
capture.output(print(results), file="aes.txt")

这篇关于有ggplot2的美学表或目录吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆