r - Applying a gradient fill on a density plot in ggplot2 -
is possible add gradient fill density plot in ggplot2, such color in chart changes along x-axis? in example below, fill
argument appears ignored.
library(ggplot2) ggplot(data.frame(x = rnorm(100)), aes(x = x, fill = x)) + geom_density()
there's option compute density hand:
set.seed(123) x <- rnorm(100) y <- density(x, n = 2^12) ggplot(data.frame(x = y$x, y = y$y), aes(x, y)) + geom_line() + geom_segment(aes(xend = x, yend = 0, colour = x)) + scale_color_gradient(low = 'green', high = 'red')
Comments
Post a Comment