I have a dataframe with columns :
X Y VALUE
I am trying to plot colors according to value ranges for example :
VALUE RANGE COLOR
0 to 2 blue
2 to 5 green
5 to 10 red
10 to 20 yellow
20 to 30 orange
> 30 grey
I am using cut from package base to create factor on the dataframe according to ranges (as suggested on http://goo.gl/W1EJzI) :
xyDataFrame$COLOUR <- cut(xyDataFrame$VALUE, c(0, 2, 5, 10, 20, 30, Inf), c("blue", "green", "red", "yellow", "orange", "grey"))
And I am plotting using the following :
ggplot2::ggplot() + ggmap::theme_nothing() +
ggplot2::geom_tile(data = xyDataFrame, alpha = 0.6, aes(x = X, y = Y, fill=COLOUR)) +
ggplot2::scale_fill_manual(values = c("blue", "green", "red", "yellow", "orange", "grey"))
The issue I am facing is that if there is no data in any particular range, then the plot is colouring the next available range with its colour. So in my case if there is no data for 0 to 2 , then plot is colouring 2 to 5 as blue if there is data for 2 to 5 range. Can you please suggest ?