colors - Control middle value colours with scale_colour_continuous using R/ggplot2 -


i have set of data , map colour aesthetic around sort of "reference value" so:

  • values below red
  • values near blue
  • values above green

i still want show fact values on continuoum, using function cut() , using scale_colour_discrete not i'm looking for. here's example data:

set.seed(123) x <- runif(100, min = 1, max = 10) y <- runif(100, min = 1, max = 10) test <- data.frame(x = x, y = y) test$colour <- runif(100, min = 1, max = 10) ggplot(test, aes(x = x, y = y, colour = colour)) + geom_point(size = 3) 

that produces following:

enter image description here

i'm familiar scale_colour_gradient(low = "red", high = "green"), hoping more deliberately transition colours along desired value mapping make regions "pop" bit more visually. spacing not linear. in other words, reference value of 3, mapping this:

value:  1     3      10 colour: red   blue   green 

is possible? i'd take alternative solutions accomplish visualization highlight "desirable" values among sea of points. example, considered replacing values near reference such (ref - tol < colour < ref + tol) <- na, , using scale_colour_gradient's option na.value.

or should considering cut() option, small cut size , figure out how gradually change colours along resultant breaks?

from http://docs.ggplot2.org/0.9.2.1/scale_gradient2.html:

scale_color_gradient2(low = "red", midpoint = 3, mid = "blue", high = "green") 

update:

concerning op's comment - playing around midpoints , space="lab" helps:

# using lab colour space improves perceptual properties # @ price of slower operation d + scale_colour_gradient2(space="lab") 

back graveyard - given newest comment realized 1 should put 2 lines of code together:

scale_color_gradient2(low = "red", midpoint = 3, mid = "blue", high = "green", space="lab") 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -