geom_bin2d heatmap grayscale

710 views
Skip to first unread message

wooster

unread,
Aug 2, 2011, 6:58:03 AM8/2/11
to ggplot2
Hi - I'm trying to draw a grayscale heatmap of the following data
frame:

length rank
1 3 42
2 3 28
3 4 50
4 4 50
5 4 50
6 4 50
7 4 35
8 4 22
9 5 50
10 5 50
11 5 50
12 5 50
13 5 50
14 5 46
15 5 23
16 5 20
17 5 19
18 6 50
19 6 50
20 6 50

With a command like so ---
ggplot(heat, aes(length, rank)) + stat_bin2d() +
opts(legend.position="none")
--- which draws a heatmap scaling from blue to red

Thought I might be able to just do this to make it grayscale instead:
ggplot(heat, aes(length, rank)) + stat_bin2d() +
opts(legend.position="none") + scale_colour_grey()

But the scale remains in colour. Please help?

thank you, Andrew

ONKELINX, Thierry

unread,
Aug 2, 2011, 7:41:49 AM8/2/11
to wooster, ggplot2
Andrew,

You need scale_fill_grey()
colour = colour of the border of the polygons
fill = colour of the face of the polygons

Best regards,

Thierry

> -----Oorspronkelijk bericht-----
> Van: ggp...@googlegroups.com [mailto:ggp...@googlegroups.com]
> Namens wooster
> Verzonden: dinsdag 2 augustus 2011 12:58
> Aan: ggplot2
> Onderwerp: geom_bin2d heatmap grayscale

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

Dennis Murphy

unread,
Aug 2, 2011, 9:41:35 AM8/2/11
to ONKELINX, Thierry, wooster, ggplot2
Hi:

The problem I got when I tried this suggestion was

ggplot(heat, aes(length, rank)) + stat_bin2d() +

opts(legend.position="none") + scale_fill_grey()
Error: Continuous variable () supplied to discrete scale_grey.

As a result, I decided to try scale_fill_gradient() with grayscale
colors for low and high:

ggplot(heat, aes(length, rank)) + stat_bin2d() +

scale_fill_gradient(limits = c(1, 10), low = 'gray80', high = 'gray20')

One can certainly toy with the values to get something better, but
this should give an idea...

HTH,
Dennis

Reply all
Reply to author
Forward
0 new messages