构建美学映射

美学映射描述了如何将数据中的变量映射到几何图形的视觉属性(美学)。美学映射可以在ggplot2()的各个层中设置。
# aes(x,y,...)

参数Arguments

x, y, … 名称-值对列表,提供映射到变量的美学。X和Y美学的名称通常被省略,因为它们很常见;所有其他美学必须命名。

值 Value

A list with class uneval. Components of the list are either quosures or constants.

细节 Details

This function also standardises aesthetic names by converting color to colour (also in substrings, e.g. point_color to point_colour) and translating old style R names to ggplot names (eg. pch to shape, cex to size).就说标准了绘图通用命名规则,把color换成colour,把pch换成shape,把cex换成size

例子

library(ggplot2)
aes(x = mpg, y = wt)
## Aesthetic mapping: 
## * `x` -> `mpg`
## * `y` -> `wt`
aes(mpg, wt)
## Aesthetic mapping: 
## * `x` -> `mpg`
## * `y` -> `wt`
You can also map aesthetics to functions of variables。还可以将美学映射到变量函数
aes(x = mpg ^ 2, y = wt / cyl)
## Aesthetic mapping: 
## * `x` -> `mpg^2`
## * `y` -> `wt/cyl`
Or to constants。或者映射到常数上
aes(x = 1, colour = "smooth")
## Aesthetic mapping: 
## * `x`      -> 1
## * `colour` -> "smooth"
美学名称是自动标准化的,如下,所有都一样
aes(col=x)
## Aesthetic mapping: 
## * `colour` -> `x`
aes(fg  =  x)
## Aesthetic mapping: 
## * `colour` -> `x`
aes(color  =  x)
## Aesthetic mapping: 
## * `colour` -> `x`
aes(color  =  x)
## Aesthetic mapping: 
## * `colour` -> `x`
注意 ! * aes()被传递给ggplot()或特定图层。提供给ggplot()的美学用作每个图层的默认值。*
ggplot(mpg, aes(displ, hwy)) + geom_point()

ggplot(mpg) + geom_point(aes(displ, hwy))