Bug with scale_fill_gradientn & rescale

703 views
Skip to first unread message

Igor S

unread,
May 8, 2012, 9:17:33 PM5/8/12
to ggplot2
Hi all,

I was just rerunning my code and noticed there have been some changes
in the ggplot2 package. Most notably muted(color) is now available
only through loading the "scales" package and in addition I found a
problem with "rescale" parameter in scale_fill_gradientn. Here's the
reproducible code of an example similar to my code, from
http://had.co.nz/ggplot2/scale_gradientn.html :

dsub <- subset(diamonds, x > 5 & x < 6 & y > 5 & y < 6)
dsub$diff <- with(dsub, sqrt(abs(x-y))* sign(x-y))
(d <- qplot(x, y, data=dsub, colour=diff))

max_val <- max(abs(dsub$diff))
values <- seq(-max_val, max_val, length = 11)

d + scale_colour_gradientn(colours = topo.colors(10), values = values,
rescale = FALSE)


This returns an error:

Error in scale$oob(scale$rescaler(x, from = limits)) :
attempt to apply non-function

So am I to understand rescale is now a function in the new package
"scales". Could anyone be so kind to provide a new syntax of setting
"rescale=FALSE" as in the previous version of ggplot2.

Thanks and much appreciated,

Igor

Dennis Murphy

unread,
May 9, 2012, 9:20:34 AM5/9/12
to Igor S, ggplot2
Hi:

Not sure, but is this what you're looking for?

library('scales')
...

d + scale_colour_gradientn(colours = topo.colors(10),
values = rescale_none(values))

HTH,
Dennis
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

Igor S

unread,
May 9, 2012, 9:37:52 AM5/9/12
to ggplot2
I figured it out. Looks like the website isn't updated yet but the R-
help is, ?scale_fill_gradientn reveals the new way to do the same

library('scales')
...
d + scale_colour_gradientn(colours = topo.colors(10),
values = values, rescaler =
function(x,...) x, oob=identity)

But thank you anyway. Too bad there is no compatibility with the code
written in previous versions. (I've got errors all over the place
since 'upgrading'.)

Best,

Igor

Ista Zahn

unread,
May 9, 2012, 9:49:51 AM5/9/12
to Igor S, ggplot2
Hi Igor,

Yes, the latest version introduced backward incompatible changes. That
is sometimes the price we pay for progress. A detailed description of
the changes from 0.8.9 to 0.9.0 is available at
http://groups.google.com/group/ggplot2-dev/attach/7512af8ea3504b17/ggplot2-0.9.0-revision6.pdf?part=3

Best,
Ista
Reply all
Reply to author
Forward
0 new messages