r - ggplot set scale_color_gradientn manually -


i have data frame this

bp        r2      log10 96162057 0.2118000 2.66514431 96162096 0.0124700 0.31749391 96162281 0.0008941 0.07012148 96163560 0.5011000 2.48505399 96163638 0.8702000 3.37778598 

and want plot bp against log10, , color points r2. r2 continuous values 0-1.

myplot <- read.cvs("mytable.csv",head=true) attach(myplot) ggplot(myplot,aes(bp,log10, color=r2)) + geom_point()  

so far, good. display r2 colors in manually selected intervals , colors, (if had discrete values).

ggplot(myplot,aes(bp,log10, color=r2)) + geom_point() +        scale_color_manual(breaks= c("1","0.8","0.6","0.4","0.2","0"),                  values = c("red","yellow","green","lightblue","darkblue")) error: continuous value supplied discrete scale 

this looks pretty, rather set colors self.

ggplot(myplot,aes(bp,log10, color=r2)) + geom_point(shape=1) +                 scale_colour_gradientn(colours = rainbow(10)) 

so, how can manually select intervals continuous values (1-0.8, 0.8-0.6, 0.6-0.4, 0.4-0.2, 0.2-0), , color them liking (red, yellow, green, light, darkblue)? smooth gradient between colors cool, not crucial.

you can use scale_colour_gradientn() , provide own colours= , values=. values give intervals each color.

ggplot(myplot,aes(bp,log10, color=r2)) + geom_point() +    scale_colour_gradientn(colours = c("red","yellow","green","lightblue","darkblue"),                          values=c(1.0,0.8,0.6,0.4,0.2,0))  

enter image description here


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -