Changing legend text for a continuous scale

1,194 views
Skip to first unread message

Jaron

unread,
Jan 10, 2012, 6:26:20 PM1/10/12
to ggplot2
I am trying to change the legend.text for a continuous scale
variable.

I have a large amount of data (~60000 records) and I want a scatter
graph to show the distribution (code below). I have used the
stat_binhex to capture this. Due to the counts varying from very
small numbers (one record per cell) up to very large counts (5000+), I
have used a log transformation in the scale_fill_continuous function.
The graph looks exactly how I want.

The legend however, report powers of 10^0, 10^0.5 etc. I would like
to over write this with my own text (eg "Very few", "Few" etc). How
do I do this? (I have spent nearly an entire day trying to find a
solution - admittedly I only started using ggplot2 on Monday and I
have produced a graph that is way better than I hoped for but I would
like to make it that little bit better :))

thanks

Jaron



d_fp_nho <- ggplot(my_data, aes(my_x,my_y)) +
scale_y_continuous(limits = c(0, 300)) + scale_x_continuous(limits =
c(0, 160)) + xlab("Before") + ylab("After") + opts(title = "FP
NHO")

FP_NHO_data <- d_fp_nho + stat_binhex(binwidth=c(2,2)) +
coord_equal(ratio = 1) + scale_fill_continuous(low="grey", high="red",
limits=c(1,5000),trans="log10")

Kohske Takahashi

unread,
Jan 10, 2012, 10:51:39 PM1/10/12
to Jaron, ggplot2
Hi, try this:

# ggplot2 0.89
ggplot(diamonds, aes(carat, price)) + stat_binhex() +
scale_fill_continuous(breaks = c(1,4,7) * 1000, labels = c("few",
"mid", "much"))

# ggplot2 0.9
ggplot(diamonds, aes(carat, price)) + stat_binhex() +
scale_fill_continuous(limits = c(0, 7) * 1000, breaks = c(1,4,7) *
1000, labels = c("few", "mid", "much"))

--
Kohske Takahashi <takahash...@gmail.com>

Research Center for Advanced Science and Technology,
The University of  Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html

2012/1/11 Jaron <jaron....@gmail.com>:

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

Reply all
Reply to author
Forward
0 new messages