gpt4 book ai didi

r - 有没有 ggplot2 的美学表格或目录?

转载 作者:行者123 更新时间:2023-12-03 05:36:48 29 4
gpt4 key购买 nike

我是 ggplot2 的新手,一直在尝试找到一个全面的美学列表。我想我理解它们的目的,但很难知道哪些可以在各种情况下使用(主要是几何图形?)。 Hadley 的网站偶尔会在各个几何图形的页面上列出可用的美学,R 文档偶尔(尽管更罕见)也会这样做。我什至发现了一个两者不太匹配的几何对象。

我通过这里的评论寻找答案,甚至买了这本书!唉,没有帮助。

我认为如果有一张表格,其中所有美学都在一个维度中列出,而所有几何(和其他对象?)在另一个维度中列出,那就太棒了。

有人知道这样的事情吗?

R 中是否有一种简单的方法(命令)来列出可应用于对象的所有美学?

表格的启动方式如下:

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

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

最佳答案

下面是每个几何对象的default_aes

            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 -- -- -- -- -- -- -- -- -- -- --

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

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")

关于r - 有没有 ggplot2 的美学表格或目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11657380/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com