How to interpret 'fill=1' in this case?

Viewed 39

I'm picturing a plot using ggplot when I came across this code:

ggplot(data.frame(Correlation=correlations),aes(x=Correlation,fill=1))+
  geom_density()+
  theme(legend.position='none')

Normally, parameter 'fill' would equal to a factor variable to differentiate each one from another, so how to interpret 'fill=1' in this case where '1' is a number?

1 Answers

The way you posted, the fill is set to the integer 1, and by default this aesthetic will be interpreted as the middle of a continuous scale running from light blue to dark blue.

Allow the legend to display, and you can see the scale:

ggplot(iris,aes(x=Sepal.Length, fill=1))+
    geom_density()

Changing the fill from an aesthetic, to a geom attribute:

  ggplot(iris,aes(x=Sepal.Length))+
    geom_density(fill=1)

Now 1 means the first color from a internally defined set of colors, in this case black, 2 would be reddish, 3 is green.

Related