To use for fills, add scale_fill_manual(values=cbPalette) # To use for line and point colors, add scale_colour_manual(values=cbPalette)
6.  # Use luminance=45, instead of default 65
ggplot(df, aes(x=cond, y=yval, fill=cond)) + geom_bar(stat="identity") + scale_fill_hue(l=40) # Reduce saturation (chromaticity) from 100 to 50, and increase luminance
ggplot(df, aes(x=cond, y=yval, fill=cond)) + geom_bar(stat="identity") + scale_fill_hue(c=45, l=80) # Note: use scale_colour_hue() for lines and points
7. trapz计算面积: library(pracma);trapz(dens$x[dens$x < 2], dens$y[dens$x < 2])