gpt4 book ai didi

R ggplot2 aes arguments - 我怎么知道哪些参数有效?

转载 作者:行者123 更新时间:2023-12-05 02:27:46 24 4
gpt4 key购买 nike

我正在学习 R,但无法找到可以放入 aes() 调用中的完整参数列表。 RStudio 帮助仅说明 aes(x, y, ...) 但“...”:我怎么知道可以放什么?

我发现通过调用 ??aes 我可以很好地了解可能发生的情况(参见此处 https://bookdown.org/yih_huynh/Guide-to-R-Book/basic-aesthetics.html ).

但我也从一门类(class)中了解到我可以使用像“group”这样的参数。示例

library(dplyr)
library(ggplot2)
library(dslabs)
data(heights)
p <- heights %>%
ggplot(aes(height, group = sex)) +
geom_density()

所以问题是:是否有我可以在美学映射中使用的完整参数列表?

最佳答案

正如@Limey 所说,这取决于您使用的 geom。在这篇文章 ( Is there a table or catalog of aesthetics for ggplot2? ) 中,@moodymudskipper 给出了一个非常好的答案来查看美学中的论点。这是一个可重现的例子:

library(ggplot2)
library(dplyr)
library(purrr)
env <- asNamespace("ggplot2")
all_geoms <- ls(envir = env, pattern = "^Geom.+")
all_geoms <- mget(all_geoms, env)

all_aes <- map(all_geoms, ~.$aesthetics())
all_aes
#> $GeomAbline
#> [1] "slope" "intercept" "colour" "size" "linetype" "alpha"
#> [7] "group"
#>
#> $GeomAnnotationMap
#> [1] "colour" "fill" "size" "linetype" "alpha" "subgroup" "group"
#>
#> $GeomArea
#> [1] "x" "y" "colour" "fill" "size" "linetype" "alpha"
#> [8] "group"
#>
#> $GeomBar
#> [1] "x" "y" "colour" "fill" "size" "linetype" "alpha"
#> [8] "group"
#>
#> $GeomBlank
#> [1] "group"
#>
#> $GeomBoxplot
#> [1] "x" "y" "lower" "xlower" "upper" "xupper"
#> [7] "middle" "xmiddle" "ymin" "xmin" "ymax" "xmax"
#> [13] "weight" "colour" "fill" "size" "alpha" "shape"
#> [19] "linetype" "group"
#>
#> $GeomCol
#> [1] "x" "y" "colour" "fill" "size" "linetype" "alpha"
#> [8] "group"
#>
#> $GeomContour
#> [1] "x" "y" "weight" "colour" "size" "linetype" "alpha"
#> [8] "group"
#>
#> $GeomContourFilled
#> [1] "x" "y" "colour" "fill" "size" "linetype" "alpha"
#> [8] "subgroup" "group"
#>
#> $GeomCrossbar
#> [1] "x" "y" "ymin" "xmin" "ymax" "xmax"
#> [7] "colour" "fill" "size" "linetype" "alpha" "group"
#>
#> $GeomCurve
#> [1] "x" "y" "xend" "yend" "colour" "size" "linetype"
#> [8] "alpha" "group"
#>
#> $GeomCustomAnn
#> [1] "xmin" "xmax" "ymin" "ymax" "group"
#>
#> $GeomDensity
#> [1] "x" "y" "fill" "weight" "colour" "alpha" "size"
#> [8] "linetype" "group"
#>
#> $GeomDensity2d
#> [1] "x" "y" "colour" "size" "linetype" "alpha" "group"
#>
#> $GeomDensity2dFilled
#> [1] "x" "y" "colour" "fill" "size" "linetype" "alpha"
#> [8] "subgroup" "group"
#>
#> $GeomDotplot
#> [1] "x" "y" "colour" "fill" "alpha" "stroke" "linetype"
#> [8] "group"
#>
#> $GeomErrorbar
#> [1] "x" "y" "ymin" "xmin" "ymax" "xmax"
#> [7] "colour" "size" "linetype" "width" "alpha" "group"
#>
#> $GeomErrorbarh
#> [1] "xmin" "xmax" "y" "colour" "size" "linetype" "height"
#> [8] "alpha" "group"
#>
#> $GeomFunction
#> [1] "x" "y" "colour" "size" "linetype" "alpha" "group"
#>
#> $GeomHex
#> [1] "x" "y" "colour" "fill" "size" "linetype" "alpha"
#> [8] "group"
#>
#> $GeomHline
#> [1] "yintercept" "colour" "size" "linetype" "alpha"
#> [6] "group"
#>
#> $GeomLabel
#> [1] "x" "y" "label" "colour" "fill"
#> [6] "size" "angle" "hjust" "vjust" "alpha"
#> [11] "family" "fontface" "lineheight" "group"
#>
#> $GeomLine
#> [1] "x" "y" "colour" "size" "linetype" "alpha" "group"
#>
#> $GeomLinerange
#> [1] "x" "y" "ymin" "xmin" "ymax" "xmax"
#> [7] "colour" "size" "linetype" "alpha" "group"
#>
#> $GeomLogticks
#> [1] "colour" "size" "linetype" "alpha" "group"
#>
#> $GeomMap
#> [1] "map_id" "colour" "fill" "size" "linetype" "alpha" "subgroup"
#> [8] "group"
#>
#> $GeomPath
#> [1] "x" "y" "colour" "size" "linetype" "alpha" "group"
#>
#> $GeomPoint
#> [1] "x" "y" "shape" "colour" "size" "fill" "alpha" "stroke"
#> [9] "group"
#>
#> $GeomPointrange
#> [1] "x" "y" "ymin" "xmin" "ymax" "xmax"
#> [7] "colour" "size" "linetype" "shape" "fill" "alpha"
#> [13] "stroke" "group"
#>
#> $GeomPolygon
#> [1] "x" "y" "colour" "fill" "size" "linetype" "alpha"
#> [8] "subgroup" "group"
#>
#> $GeomQuantile
#> [1] "x" "y" "weight" "colour" "size" "linetype" "alpha"
#> [8] "group"
#>
#> $GeomRaster
#> [1] "x" "y" "fill" "alpha" "group"
#>
#> $GeomRasterAnn
#> [1] "group"
#>
#> $GeomRect
#> [1] "xmin" "xmax" "ymin" "ymax" "colour" "fill"
#> [7] "size" "linetype" "alpha" "group"
#>
#> $GeomRibbon
#> [1] "x" "y" "ymin" "xmin" "ymax" "xmax"
#> [7] "colour" "fill" "size" "linetype" "alpha" "group"
#>
#> $GeomRug
#> [1] "colour" "size" "linetype" "alpha" "x" "y" "group"
#>
#> $GeomSegment
#> [1] "x" "y" "xend" "yend" "colour" "size" "linetype"
#> [8] "alpha" "group"
#>
#> $GeomSf
#> [1] "geometry" "shape" "colour" "fill" "size" "linetype" "alpha"
#> [8] "stroke" "group"
#>
#> $GeomSmooth
#> [1] "x" "y" "colour" "fill" "size" "linetype"
#> [7] "weight" "alpha" "ymin" "ymax" "group"
#>
#> $GeomSpoke
#> [1] "x" "y" "angle" "radius" "colour" "size" "linetype"
#> [8] "alpha" "group"
#>
#> $GeomStep
#> [1] "x" "y" "colour" "size" "linetype" "alpha" "group"
#>
#> $GeomText
#> [1] "x" "y" "label" "colour" "size"
#> [6] "angle" "hjust" "vjust" "alpha" "family"
#> [11] "fontface" "lineheight" "group"
#>
#> $GeomTile
#> [1] "x" "y" "fill" "colour" "size" "linetype"
#> [7] "alpha" "width" "height" "group"
#>
#> $GeomViolin
#> [1] "x" "y" "weight" "colour" "fill" "size" "alpha"
#> [8] "linetype" "group"
#>
#> $GeomVline
#> [1] "xintercept" "colour" "size" "linetype" "alpha"
#> [6] "group"

reprex package 创建于 2022-07-11 (v2.0.1)

关于R ggplot2 aes arguments - 我怎么知道哪些参数有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72936787/

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