I have some geographic x,y,z data which I plot as follows
p<-ggplot(aes(x=x,y=y,fill=z),data=my_data)
I then apply a gradient
p<-p + scale_fill_gradient(low = "pink", high = "green")
And then tile and display the data
p<-p + geom_tile()
p
This works and gives the following:
One would think then, that I could replace the scale_fill_gradient()
call with any number of other options such as
p<-p + scale_color_hue()
p<-p + scale_colour_gradientn(colours=c("#E5F5F9","#99D8C9","#2CA25F"))
p<-p + scale_colour_gradientn(colours = rainbow(7))
p<-p + scale_colour_brewer()
would work.
But they don't, all I get is a gradient of blue.
Any thoughts as to why this might be, and how I can generate lots of happy colours?
If we want to create a color range in R, we can use the colorRampPalette function. In the previous R code, we have defined a new function called fun_color_range, which can be used to generate color ranges from the color with the color code #1b98e0 to red. The color codes are now stored in the data object my_colors.
Format cells by using color scales On the Home tab, click Conditional Formatting. Point to Color Scales, and then click the color scale format that you want. The top color represents larger values, the center color, if any, represents middle values, and the bottom color represents smaller values.
By default, ggplot2 chooses to use a specific shade of red, green, and blue for the bars.
There are two versions of these scale functions, one for colour
and one for fill
. You just needed to use the fill
versions, i.e. scale_fill_hue
, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With