10

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:

enter image description here

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?

Richard
  • 56,349
  • 34
  • 180
  • 251
  • 1
    To expand on what joran said, if you replace the word `color` in all of those examples with the word `fill` I think you'll find you can generate all your "happy colours" – Justin Jul 03 '12 at 17:13
  • Thanks @Justin, this seems to be changing the outline color of my geom_tiles... so I need a way to map the `scale_colour` commands to the tile's fill property... – Richard Jul 03 '12 at 17:24
  • Thanks @joran, that's so obvious in retrospect, but it's just affecting the outline of the cells, as in the comment I left Justin. I'll upload a picture. – Richard Jul 03 '12 at 17:24
  • Erm, use `scale_colour_*` to change the color and `scale_fill_*` to change the fill. – joran Jul 03 '12 at 17:26
  • @joran, I got things working off of your comments. Could you please write them up as an answer? If it seems in complete, I'll edit it appropriately. Thanks! – Richard Jul 03 '12 at 17:53

1 Answers1

6

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.

joran
  • 169,992
  • 32
  • 429
  • 468