Plotting colours in R according to values -


i have dataframe columns x , y , value. using ggplot2 plot values @ specified coordinates. wish fill colour based on custom ranges value column. example :

value    colour 0 2    blue 2 5    green 5 10   red 10 20  yellow 20 30  orange 30 40  grey >40       black 

how fill specific colour particular values using ggplot2 ?

i can resample data if required , map individual resampled value colours after that, example :

value    resampled value    colour 0 2        10             blue 2 5        20             green 5 10       30             red 10 20      40             yellow 20 30      50             orange 30 40      60             grey >40           70             black 

but values not getting mapped colours code :

ggplot2::ggplot() + ggmap::theme_nothing() + ggplot2::geom_tile(data = xydataframe, alpha = 0.6, aes(x = x, y = y, fill=value)) +  ggplot2::scale_fill_gradientn(colours = c("blue", "green", "red", "yellow", "orange", "grey", "black")) 

you should use cut make additional variable in data frame.

data$colour <- cut(data$value, c(0, 2, 5, 10, 20, 30, 40, inf),     c("blue", "green", "red", "yellow", "orange", "grey", "black")) 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -