What does the ".." in ggplot "fill = .. density .." mean?

I work through The R Graphics Cookbook and run this set of code:

library(gcookbook) library(ggplot2) p <- ggplot(faithful, aes(x = eruptions, y = waiting)) + geom_point() + stat_density2d(aes(alpha=..density.., fill=..density..), geom="tile", contour=FALSE) 

It works fine, but I don’t understand what it refers to .. before and after density . It seems I can not find it in the book.

+6
source share
1 answer

In R, variable names starting with .. possible, and are treated like any other variable. Trying to create one of yours.

 ..x.. <- 1:5 

ggplot2 often creates the addition of extra columns to your chart data frame. (In ggplot2 terminology ggplot2 this is β€œdata fortification.”) ggplot2 uses the ..something.. naming ..something.. for these fortified columns.

This is partly due to the fact that using ..something.. unlikely to ..something.. with existing variables in your dataset. Take this as a hint that you should not specify columns in your dataset using this template.

The stat_density* functions use ..density.. to represent the density of the variable x. Other enriched variable names include ..count..

+5
source

All Articles