combining legends with scale_fill_grey + scale_shape_manual

241 views
Skip to first unread message

Ben Bolker

unread,
Feb 11, 2010, 9:28:22 AM2/11/10
to ggplot2
When I draw the following example graph, I am hoping for a
single legend with the point shapes and grey scales changing
in common (i.e. a black circle for c=0.1, a dark grey square
for c=0.2, a medium grey diamond for c=0.3, and so forth).
Instead I get two legends -- one full of black circles (should be
changing shades of grey?) and one with unfilled shapes.
Does anyone have insights/workarounds? (I tried explicitly
naming the scales, that didn't seem to make a difference.)

d <- data.frame(x=1:5,y=1:5,c=factor(seq(0.1,0.5,by=0.1)))
library(ggplot2)
ggplot(d,aes(x=x,y=y,shape=c,fill=c))+
geom_point(size=5)+
scale_fill_grey(start=0.1,end=0.9)+
scale_shape_manual(values=21:25)

cheers
Ben Bolker

hadley wickham

unread,
Feb 11, 2010, 11:14:46 PM2/11/10
to Ben Bolker, ggplot2
Hi Ben,

Looks like a bug. I'll look into it.

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

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

hadley wickham

unread,
Feb 15, 2010, 3:59:57 PM2/15/10
to Ben Bolker, ggplot2
> Looks like a bug.  I'll look into it.

Yes, it was a bug that prevented any scale created with scale_manual
from correctly merging with legends produced by other scales. It's
fixed in the development version, which I'm hoping to release very
soon.

Regards,

Hadley

elaliberte

unread,
Feb 16, 2010, 2:34:59 PM2/16/10
to ggplot2
Strange. Using ggplot2 version 0.8.3 under R 2.10.1, Ben's code worked
perfectly and generated only one legend, which looks fine (i.e. it
combines both fill and shape). Why then, would it work on my setup but
not on his?

Ben Bolker

unread,
Feb 16, 2010, 2:44:50 PM2/16/10
to elaliberte, ggplot2
I was using v. 0.8.5 under 2.10.1, maybe it was a newly introduced bug ...

cheers
Ben


--
Ben Bolker
Associate professor, Biology Dep't, Univ. of Florida
bol...@ufl.edu / people.biology.ufl.edu/bolker
GPG key: people.biology.ufl.edu/bolker/benbolker-publickey.asc

signature.asc

hadley wickham

unread,
Feb 16, 2010, 4:02:04 PM2/16/10
to Ben Bolker, elaliberte, ggplot2
The fact that it ever worked was a bug disguising the fact that
legends were being combined inappropriately.

Hadley

Reply all
Reply to author
Forward
0 new messages