Reputation: 107
I am trying to visualize the diamonds data from ggplot2 in a histogram where I show the distribution of carats.
I've tried to move the aes values from ggplot to geom_histogram(), to try ..fill.., and to manipulate the code in different ways but the result is the same.
histogram<- ggplot(diamonds, aes(x=carat, fill=carat)) +
geom_histogram(binwidth = 0.1) + scale_fill_gradient(low='blue', high='yellow')
I would expect to see my histogram go from blue to yellow as the carats increase but I still see it in grey.
Upvotes: 2
Views: 1259
Reputation: 5201
Try with fill=..x..
:
ggplot(diamonds, aes(x=carat, fill=..x..)) +
geom_histogram(binwidth = 0.1) + scale_fill_gradient(low='blue', high='yellow')
Upvotes: 5