..x ..在ggplot表示法中代表什么

我经常在ggplot或ggridges中看到类似的符号:

考虑通用df

ggplot(df,aes ( x = x,y = factor(y),fill = ..x.. ) )

..x..在上面的代码中代表什么?

ccpig520520 回答:..x ..在ggplot表示法中代表什么

在构建绘图时,ggplot2会创建一个data.frame,其中包含绘图所需的所有数据。该符号可用于访问该data.frame的列。您没有提供完整的示例,因此我将以stat_summary进行显示:

library(ggplot2)
p <- ggplot(mtcars,aes(cyl,mpg,color = ..ymin..)) + 
  stat_summary(fun.data = "mean_cl_boot",size = 2)
print(p)

resulting plot

g <- ggplot_build(p)
g$data
#[[1]]
#   colour x group        y     ymin     ymax PANEL size linetype shape fill alpha stroke
#1 #56B1F7 4    -1 26.66364 24.23614 29.19114     1    2        1    19   NA    NA      1
#2 #316794 6    -1 19.74286 18.77107 20.74321     1    2        1    19   NA    NA      1
#3 #132B43 8    -1 15.10000 13.75696 16.30714     1    2        1    19   NA    NA      1

如您所见,stat_summary计算ymin的值,我们可以将color映射到此(内部)变量。

本文链接:https://www.f2er.com/3119857.html

大家都在问