Color code points based on percentile in ggplot

后端 未结 3 991
醉酒成梦
醉酒成梦 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:28

    I´m not sure if this is what you are searching for, but maybe it helps:

    # a little function which returns factors with three levels, normal, 95% and 99%
    qfun <- function(x, qant_1=0.95, qant_2=0.99){
      q <- sort(c(quantile(x, qant_1), quantile(x, qant_2)))
      factor(cut(x, breaks = c(min(x), q[1], q[2], max(x))))
    }
    
    
    df <- data.frame(samp=rnorm(1000))
    
    ggplot(df, aes(x=1:1000, y=df$samp)) + geom_point(colour=qfun(df$samp))+
      xlab("")+ylab("")+
      theme(plot.background = element_blank(),
            panel.background = element_blank(),
            panel.border = element_blank(),
            legend.position="none",
            legend.title = element_blank())  
    

    as a result I gotenter image description here

提交回复
热议问题