[R] Choosing the number of colour breaks in ggplot2

Karl Ove Hufthammer Karl.Hufthammer at math.uib.no
Fri Jul 13 15:48:02 CEST 2007


A seemingly simple problem has me stumped. Is it possible to choose the
number of colour breaks for a gradient scale in the current version of
ggplot2?

Here is a simple example:

---------------------------------------------
x=-10:10
y=-10:10
dat=expand.grid(x=x,y=y)
dat$z=dat$x^2+dat$y^2-100

ggplot(dat, mapping=aes(x=x, y=y, fill=z)) +
  geom_tile() + scale_fill_gradient2()
---------------------------------------------

The image shows many (61) colours, but only 5 of them are shown in the
legend. How do I change the legend to show, say, 10 colours?

-- 
Karl Ove Hufthammer



More information about the R-help mailing list