Actually aesthetics can vary with geom_ribbon(...)
(or geom_area(...)
, which is basically the same thing), as long as you set the group
aesthetic as well.
delta <- 0.001
quantiles <- 10
z.df <- data.frame(x = seq(from=-3, to=3, by=delta))
z.df$pdf <- dnorm(z.df$x)
z.df$qt <- cut(pnorm(z.df$x),breaks=quantiles,labels=F)
library(ggplot2)
ggplot(z.df,aes(x=x,y=pdf))+
geom_area(aes(x=x,y=pdf,group=qt,fill=qt),color="black")+
scale_fill_gradient2(midpoint=median(unique(z.df$qt)), guide="none") +
theme_bw()
Setting quantiles <- 20
at the beginning produces this:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…