Applying a gradient fill on a density plot in ggplot2

Viewed 4425

Is it possible to add a gradient fill to a density plot in ggplot2, such that the color in the chart changes along the x-axis? In this example below, the fill argument appears to be ignored.

library(ggplot2)
ggplot(data.frame(x = rnorm(100)), aes(x = x, fill = x)) + geom_density()
2 Answers
Related