log-scaled colour palette for geom_raster

1,913 views
Skip to first unread message

Johannes Radinger

unread,
May 9, 2012, 5:27:10 AM5/9/12
to ggp...@googlegroups.com
Hi,

I tried the "new" geom_raster for displaying some raster maps (created by GIS). The import and transformation to a dataframe into R and the plot in ggplot2 works really fine and was quite easy to do...so far I am really happy. Now the topic of color-schemes and palettes is really new...

I can get a new color gradient for my raster plot with scale_fill_gradient() resp. scale_fill_gradient() for a more customized way, I that correct so far?

Now I just wanted to know if there is a log-scaled color gradient available or is there any option I can set? My raster maps consists of many very small values and only a few large values and to show differences in the small values, such a log.scaled gradient would be very good. Of course the colors at the ends of the gradient are not important at this time (the gradient is showing probability; range from 10^-8 to 10^-1).

Here a small example with log-data (lots of small, few larger ones):

x <- seq(1,100)
df <- expand.grid(x=x, y=x)
df$z <- exp(runif(10000,log(0.00000001),log(100)))

base <- ggplot(df, aes(x, y, fill = z))
base + geom_raster()


Has anyone done similar things so far and can come up with an example of a nice color-palette/gradient?

best regards,

Johannes
--
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

Brandon Hurr

unread,
May 9, 2012, 5:56:53 AM5/9/12
to Johannes Radinger, ggp...@googlegroups.com
I'm probably misunderstanding, but could you transform your df$z into something that could be handled more easily by the scale to give you what you want and then use it for your scale?

I've been trying to play with it but it doesn't like me or my log()'s. 

Brandon

--
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

Johannes Radinger

unread,
May 9, 2012, 6:04:59 AM5/9/12
to Brandon Hurr, ggp...@googlegroups.com
Hi Brandon,

Problem solved:
I found what i was looking for. One can set
trans="" for the color-gradient. This is really
easy but I thought that transformations are just
for axis but it also worked for the gradient-scales:

+scale_fill_gradient(trans = 'log')

I found that somewhere in the history of this mailing list:
http://groups.google.com/group/ggplot2/browse_thread/thread/5ac9f7d7c8ae7384

Anyway thank you for your help,

Best regards.

/johannes

-------- Original-Nachricht --------
> Datum: Wed, 9 May 2012 10:56:53 +0100
> Von: Brandon Hurr <brando...@gmail.com>
> An: Johannes Radinger <JRad...@gmx.at>
> CC: ggp...@googlegroups.com
> Betreff: Re: log-scaled colour palette for geom_raster

Brandon Hurr

unread,
May 9, 2012, 6:07:26 AM5/9/12
to Johannes Radinger, ggp...@googlegroups.com
Yes, that's very useful. Thanks for reporting back. 

On Wed, May 9, 2012 at 11:04 AM, Johannes Radinger <JRad...@gmx.at> wrote:
+scale_fill_gradient(trans = 'log')

Reply all
Reply to author
Forward
0 new messages