Removing one of two legends

71 views
Skip to first unread message

AC Del Re

unread,
Nov 22, 2009, 5:55:54 PM11/22/09
to ggp...@googlegroups.com
Hi All,

I have produced a graph (attached and code below) with 2 legends but I would like to remove one of them entirely (wt.del). How can I do this? When I add: opts(legend.position="none") the entire legend is removed, which is not what I desire. 

Thank you,

AC Del Re


p<-qplot(n.sess,del,data=grief2, weight=wt.del,size=wt.del,shape=factor(risk))
p + geom_smooth(aes(group=1),method = lm, se = F)+
    xlab("Sessions")+ylab("Effect Size")+ 
    scale_shape(solid = FALSE, name="Risk Level",
    breaks = c("1", "2", "3"), labels = c("Normal", "At-risk", 
    "Chronic"))+
    scale_size(to = c(4, 10))+
    opts(title='ES Differences by Group & Sessions',
    plot.title=theme_text(size=13,face="bold"))

temp.jpeg

hadley wickham

unread,
Nov 22, 2009, 10:52:57 PM11/22/09
to AC Del Re, ggp...@googlegroups.com
This isn't currently possible with ggplot2. Can you say why you want
to remove 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



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

AC Del Re

unread,
Nov 22, 2009, 11:04:20 PM11/22/09
to hadley wickham, ggp...@googlegroups.com
Hmm, that's unfortunate. Is there any workaround? 

I want to remove the wt.del legend because it lacks meaning in this graph. I'm conducting a meta-analysis and each point represents a study weighted by  wt.del ( =  the inverse of each study's effect size variance) and the way its represented in the graph is confusing.

BTW, thanks for the answer to my prior post!

AC

Ian Fellows

unread,
Nov 22, 2009, 11:05:19 PM11/22/09
to hadley wickham, AC Del Re, ggp...@googlegroups.com
I can't say why the questioner wishes to remove it, but I ran up
against the same thing.
library(Deducer)
data(mtcars)
corr.mat<-cor.matrix(variables=c(mpg,cyl,disp,hp,drat),,
data=mtcars,
test=cor.test,
method='spearman',
alternative="two.sided",
exact=FALSE)
plot(corr.mat,size=16)

Th above code creates circle plots, with size indicating magnitude.
color (blue to red), also indicates magnitude as well as direction.
Therefore the size legend is redundant and can be removed without loss
of information or understanding.

Ian

hadley wickham

unread,
Nov 23, 2009, 8:32:25 AM11/23/09
to AC Del Re, ggp...@googlegroups.com
> I want to remove the wt.del legend because it lacks meaning in this graph.
> I'm conducting a meta-analysis and each point represents a study weighted by
>  wt.del ( =  the inverse of each study's effect size variance) and the way
> its represented in the graph is confusing.

I don't understand. If you remove the legend how will people
understand what size means? In what way is the current legend
confusing?

Hadley


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

hadley wickham

unread,
Nov 23, 2009, 8:34:01 AM11/23/09
to Ian Fellows, AC Del Re, ggp...@googlegroups.com
> Th above code creates circle plots, with size indicating magnitude.
> color (blue to red), also indicates magnitude as well as direction.
> Therefore the size legend is redundant and can be removed without loss
> of information or understanding.

The size legend isn't redundant because it tells people what size is
mapped to! How else are they supposed to know? Have you considered
mapping colour to sign(cor) and size to abs(cor) ?

Hadley

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

AC Del Re

unread,
Nov 23, 2009, 1:04:06 PM11/23/09
to ggplot2
I plan on noting at the bottom of the graph that the point size is
proportional to 1/var(effect size), which is the weighting factor for
that study in the meta-analysis-- and 1/var(del) is rougly
proportional to sample size (N). Then a range of Ns for these studies
will be given in the note which will provide meaningful information to
give an idea of the range of values represented by point size.

The current wt.del legend seems distracting to me and is not needed
when a similar explanation as above is given. The legend values
ranging from 10 to 80 and are not particularly meaningful and the
circle points in the legend key do not match up with the shapes in the
graph. Do others see this legend being unnecessary and somewhat
confusing?

Thanks,

AC

hadley wickham

unread,
Nov 23, 2009, 1:07:59 PM11/23/09
to AC Del Re, ggplot2
> I plan on noting at the bottom of the graph that the point size is
> proportional to 1/var(effect size), which is the weighting factor for
> that study in the meta-analysis-- and 1/var(del) is rougly
> proportional to sample size (N).  Then a range of Ns for these studies
> will be given in the note which will provide meaningful information to
> give an idea of the range of values represented by point size.

In that case, why not map size to N? There's clearly something I'm
missing here.

Hadley

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

AC Del Re

unread,
Nov 23, 2009, 1:52:38 PM11/23/09
to hadley wickham, ggplot2
 Well, I'm wanting to be as precise as possible with the weighting (being 1/var(del)). Beyond that, it gets complicated because we're using a mean differences procedure (treatment group pre-post change - control group pre-post change) and some of our control groups are imputed. Therefore, the actual sample size is different from the respective study's weighting in the meta.   

AC

AC Del Re

unread,
Nov 29, 2009, 8:55:59 PM11/29/09
to hadley wickham, ggplot2
Hi All,

Im checking in again regarding the removal of one of two legends in a plot. Does anyone know of a potential workaround? I don't mean to harp on this topic but I need to remove one of the legends (wt.del) but would prefer to stick with ggplot2 for generating this graph!  

Thanks,

AC

hadley wickham

unread,
Dec 1, 2009, 5:27:37 PM12/1/09
to AC Del Re, ggplot2
Ok, that makes sense to me, and I'll definitely consider it for a
future version. However, I don't have any suggestions on how to
remove it, unless you want to resort to some grid hackery.

Hadley

AC Del Re

unread,
Dec 1, 2009, 10:09:26 PM12/1/09
to hadley wickham, ggp...@googlegroups.com
Thanks for the consideration, Hadley. Can you (or others) point me in the right direction (prior posts, other sites, etc) to start on this grid hacking?? 

AC

hadley wickham

unread,
Dec 3, 2009, 7:51:59 PM12/3/09
to AC Del Re, ggp...@googlegroups.com
The grid appendix would be the best place to start -
http://had.co.nz/ggplot2/book/appendices.pdf

And I've added a feature request at
http://github.com/hadley/ggplot2/issues/labels/scale#issue/27 to make
it possible to disable legends. You can use that page to track
progress.

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

Matthieu Dubois

unread,
Dec 4, 2009, 1:29:47 PM12/4/09
to ggplot2
You may also post-editing the plot outside of R, in a vector drawing
piece of software (with e.g. Adobe Illustrator or Inkscape) to get rid
of what you want. This is not particularly elegant, but will do the
trick.

Matthieu



On 1 déc, 22:09, AC Del Re <acde...@gmail.com> wrote:
> Thanks for the consideration, Hadley. Can you (or others) point me in the
> right direction (prior posts, other sites, etc) to start on this grid
> hacking??
>
> AC
>
>
>
> On Tue, Dec 1, 2009 at 4:27 PM, hadley wickham <h.wick...@gmail.com> wrote:
> > Ok, that makes sense to me, and I'll definitely consider it for a
> > future version.  However, I don't have any suggestions on how to
> > remove it, unless you want to resort to some grid hackery.
>
> > Hadley
>
> > On Mon, Nov 23, 2009 at 12:52 PM, AC Del Re <acde...@gmail.com> wrote:
> > >  Well, I'm wanting to be as precise as possible with the weighting (being
> > > 1/var(del)). Beyond that, it gets complicated because we're using a mean
> > > differences procedure (treatment group pre-post change - control group
> > > pre-post change) and some of our control groups are imputed. Therefore,
> > the
> > > actual sample size is different from the respective study's weighting in
> > the
> > > meta.
> > > AC
>
> > > On Mon, Nov 23, 2009 at 12:07 PM, hadley wickham <h.wick...@gmail.com>
> > > wrote:
>
> > >> > I plan on noting at the bottom of the graph that the point size is
> > >> > proportional to 1/var(effect size), which is the weighting factor for
> > >> > that study in the meta-analysis-- and 1/var(del) is rougly
> > >> > proportional to sample size (N).  Then a range of Ns for these studies
> > >> > will be given in the note which will provide meaningful information to
> > >> > give an idea of the range of values represented by point size.
>
> > >> In that case, why not map size to N?  There's clearly something I'm
> > >> missing here.
>
> > >> Hadley
>
> > >> --
> > >>http://had.co.nz/
>
> > > --
> > > 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<ggplot2%2Bunsu...@googlegroups.com>
Reply all
Reply to author
Forward
0 new messages