scale_fill_brewer problem with continuous data

5,615 views
Skip to first unread message

Neil Best

unread,
Dec 30, 2010, 6:02:48 PM12/30/10
to ggplot2
I was working on a geom_tile() plot and could not get
scale_fill_brewer to work.

I started with . . .

scale_fill_continuous( "", limits= c( 0, 100), low= "yellow", high=
"green")

. . . and got approximately what I wanted but the palette wasn't quite
right.

When I added . . .

scale_fill_brewer( "", palette="YlGn", limits= c( 0,100), breaks=
seq(0,100,by=20))

. . . I got two colors that appear to be from the middle of the
palette mapped to the limits and no fills for the intermediate values.

To get it to work I had to write . . .

seqTheme <- colorRampPalette( brewer.pal( 5, "YlGn"),
space="Lab")

. . . and then add to my plot . . .

scale_fill_gradientn( colours= seqTheme( 5),
limits= c( 0, 100),
breaks= seq( 0, 100, by= 20))


Is this a bug or am I doing something wrong? Thanks.

Kohske Takahashi

unread,
Dec 30, 2010, 9:44:55 PM12/30/10
to Neil Best, ggplot2
Hi,

Probably scale_fill_brewer and scale_colour_brewer are designed to use
with categorical (i.e., discrete) variable.

scale_fill_gradientn() is suitable, and you can do it simply by

p <- ggplot(data.frame(x=0:100, y=0), aes(x, y, fill=x)) + geom_tile() +
scale_fill_gradientn(colours=brewer.pal(7,"YlGn"))

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

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