Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
and I want to plot BP against LOG10, and color the points by R2. R2 are continuous values from 0-1.
myplot <- read.cvs("mytable.csv",head=TRUE)
attach(myplot)
ggplot(myplot,aes(BP,LOG10, color=R2)) + geom_point()
So far, so good. However I would like to display the R2 colors in manually selected intervals and colors, like this (if I 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 to discrete scale
This looks pretty, but I would rather set the colors my self.
ggplot(myplot,aes(BP,LOG10, color=R2)) + geom_point(shape=1) +
scale_colour_gradientn(colours = rainbow(10))
So, how can I manually select intervals from continuous values (1-0.8, 0.8-0.6, 0.6-0.4, 0.4-0.2, 0.2-0), and color them to my liking (red, yellow, green, light, darkblue)? A smooth gradient between the colors would be cool, but not crucial.
You can use scale_colour_gradientn() and then provide your own colours= and values=. Values will give intervals for 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))
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.