Color code points based on percentile in ggplot

后端 未结 3 1051
醉酒成梦
醉酒成梦 2021-01-25 19:11

I have some very large files that contain a genomic position (position) and a corresponding population genetic statistic (value). I have successfully plotted these values and wo

3条回答
  •  半阙折子戏
    2021-01-25 19:18

    You can achieve this slightly more elegantly by incorporating quantile and cut into the aes colour expression. For example col=cut(d,quantile(d)) in this example:

    d = as.vector(round(abs(10 * sapply(1:4, function(n)rnorm(20, mean=n, sd=.6)))))
    
    ggplot(data=NULL, aes(x=1:length(d), y=d, col=cut(d,quantile(d)))) + 
      geom_point(size=5) + scale_colour_manual(values=rainbow(5))
    

    enter image description here

    I've also made a useful workflow for pretty legend labels which someone might find handy.

提交回复
热议问题