Hexbin plot in grey scale

393 views
Skip to first unread message

Bob

unread,
Dec 7, 2009, 3:51:13 PM12/7/09
to ggplot2
Hi All,

I need to do a hexbin plot in greyscale for publication. It works fine
in color (working example below), but when I add scale_fill_grey() to
it, it generates an error message. In Googling about on this I found
http://learnr.files.wordpress.com/2009/08/latbook.pdf, which
duplicates Lattice examples in ggplot2, but the hexbin plots from
Lattice are in grey but the author leaves the ggplot2 plots in color.
That makes me wonder if it's possible to do them in grey.

Any ideas?

Thanks,
Bob

# Generate some data:
pretest2 <- round( rnorm( n=5000, mean=80, sd=5) )
posttest2 <- round( pretest2 + rnorm( n=5000, mean=3, sd=3) )
pretest2[pretest2>100] <- 100
posttest2[posttest2>100] <- 100
temp=data.frame(pretest2,posttest2)

# This works fine, but is in color:
ggplot(temp, aes(pretest2, posttest2)) +
geom_hex( bins=30 )

# Adding scale_fill_grey() yields,
# "Error: Continuous variable () supplied to discrete scale_grey."
ggplot(temp, aes(pretest2, posttest2)) +
geom_hex( bins=30 ) + scale_fill_grey()

hadley wickham

unread,
Dec 7, 2009, 3:52:36 PM12/7/09
to Bob, ggplot2
Hi Bob,

scale_fill_grey is for discrete variables. You probably want:
scale_fill_continuous(low = "grey80", high = "black")

Hadley
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2



--
http://had.co.nz/

Bob

unread,
Dec 8, 2009, 10:41:12 AM12/8/09
to ggplot2
Hi Hadley,

That did it!

Thanks,
Bob
Reply all
Reply to author
Forward
0 new messages