2

I came across the Microsoft Edx R Data Science MOOC plotting chapter and I stumbled on their sample code with 2 dots before & after a token. What could this mean?

I've searched around the net for some answers to this but found none. The closest I got was 2 dots before a numeric token which made the token a sequence placeholder for parameters passed in.

plot_hist_grid = function(df, numcols, bins = 10){
    options(repr.plot.width=6, repr.plot.height=3) # Set the initial plot area dimensions
    for(col in numcols){
        if(is.numeric(df[,col])){
            bw = (max(df[,col]) - min(df[,col]))/(bins + 1)
            p = ggplot(df, aes_string(col)) + 
                       geom_histogram(binwidth = bw, aes(y=..density..), alpha = 0.5) +
                       geom_density(aes(y=..density..), color = 'blue') + 
                       geom_rug() +
                       facet_grid(. ~ drive.wheels)
            print(p)
        }
    }
}

plot_hist_grid(auto_prices, numcols)
  • I just want to know the meaning of the 2 dots before & after the token "density" in the ggplot statement.
joran
  • 169,992
  • 32
  • 429
  • 468
  • 1
    This seems to answer it https://stackoverflow.com/questions/17502808/double-dots-in-a-ggplot ? – Frank Jun 19 '19 at 14:35
  • 1
    It's the (now old) way that ggplot would denote a computed variable available to be plotted. The use of the dots is just to avoid collisions with other variable/object names. That method was dropped recently, though, in favor of something like `y = stat(density)`. If you look up `?geom_density` you'll see a list of "computed variables". – joran Jun 19 '19 at 14:35
  • 2
    Also see here: https://stackoverflow.com/questions/14570293/special-variables-in-ggplot-count-density-etc – Jon Spring Jun 19 '19 at 14:35

0 Answers0