Richard
Richard

Reputation: 61479

Color Gradients With ggplot

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?

Upvotes: 10

Views: 13161

Answers (1)

joran
joran

Reputation: 173697

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.

Upvotes: 6

Related Questions