Home > OS >  What does fill=..level.. mean in ggplot?
What does fill=..level.. mean in ggplot?

Time:03-02

I want to create a "heating map" for a dataset, which contains obs about shooting in NYC Boroughs.

ggmap(nyc_map) 
  stat_density2d(data = NYPD,
                 aes(x = Longitude, y = Latitude, fill= ..level..), 
                 alpha=0.08,
                 bins=30,
                 geom = "polygon")   
  scale_fill_gradient(low = "red", high = "green", name="Shootings level")   
  scale_alpha(range = c(0, 0.08), guide = "none")  
  scale_size(range = c(0,0.75))  
  ggtitle("Shootings for Boroughs") 
  
  
  theme(axis.ticks = element_blank(),
        axis.text = element_blank(),
        legend.position="right")  
 theme(plot.title = element_text(hjust = 0.5))

In that case, what does fill=..level.. means?? Because I don't have a variable for the number of shootings, I have the number of rows and the lat and long for Boroughs. Should fill=..level.. mean about mean of the shootings?

enter image description here

CodePudding user response:

The dot-dot notation ..some_var.. allows to access statistics computed by ggplot to construct the plot. In this case, the levels for the 2d-density. You can, instead, extract and use them with stat(): see related question on RStudio community

  • Related