Re: scale_shape question

76 views
Skip to first unread message

Winston Chang

unread,
Aug 30, 2012, 9:44:12 PM8/30/12
to Tom A., ggp...@googlegroups.com
You could use the filled shapes (21-25) and the use a fill scale where
one of the fill colors is NA.:

ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point(aes(shape=factor(vs), fill=factor(am))) +
scale_shape_manual(values=c(21, 22)) +
scale_fill_manual(values=c(NA, "black"))

For a list of point shapes:
http://wiki.stdout.org/rcookbook/Graphs/Shapes%20and%20line%20types/

-Winston

On Wed, Aug 29, 2012 at 12:07 PM, Tom A. <ande...@gmail.com> wrote:
> Hello all,
> I am attempting to create a scatterplot where I want to show two different
> factors simultaneously, with four (Dens.AMAN in code below) and two
> (Dens.AMMA) levels of each factor, respectively. I was hoping to do this
> using four symbols that can be either open or closed (e.g. circle, square,
> triangle, diamond). Is there a way to specify a subset of data points
> within shape_solid() to become open or closed? Or would this be done more
> simply in scale_shape_manual()? Any help or advice on where to look would
> be greatly appreciated.
>
> ggplot(test1,aes(AMAN.surv,Mean.SVL))+geom_point(aes(size=2,shape=as.factor(Dens.AMMA)))+
>
> stat_smooth(method="lm",color="black",aes(lty=as.factor(Dens.AMMA)))+theme_bw()+scale_shape(solid=F)+
> opts(panel.grid.major = theme_line(colour=NA ),panel.grid.minor =
> theme_line(colour = NA))
>
> Cheers,
> Tom
>
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
point.png

Tom A.

unread,
Aug 31, 2012, 12:15:27 PM8/31/12
to ggp...@googlegroups.com, Tom A.
Thanks so much the link and example, that worked perfectly.

Winston Chang

unread,
Nov 27, 2012, 10:37:30 PM11/27/12
to Tom A., ggplot2
Revisiting this one because I realized there was a problem with the legend. In the code I supplied previously, the legend for fill used the default point shape, 16. This point shape only usees 'colour' and not 'fill', and so both points in the legend are black.

Here's a fixed version. It uses guide_legend to specify the shape used in the legend. (I also changed the shapes to make them easier to distinguish.)

ggplot(mtcars, aes(x=wt, y=mpg)) +
    geom_point(aes(shape=factor(vs), fill=factor(am))) +
    scale_shape_manual(values=c(21, 24)) +
    scale_fill_manual(values=c(NA, "black"), 
        guide=guide_legend(override.aes=list(shape=21)))


-Winston
bad_legend.png
good_legend.png
Reply all
Reply to author
Forward
0 new messages