completely remove legend

21,104 views
Skip to first unread message

squid

unread,
Aug 31, 2009, 8:10:07 AM8/31/09
to ggplot2
Hi,
Is there an easy way to entirely remove the legend? I want to print a
few graphs on one page and only need the legend there once per row.


pdf(file="test.pdf", width=12, height=8)
pushViewport(viewport(layout = grid.layout(2, 2)))

a<- ggplot(data=all , aes(block)) +
geom_line(aes(y=x.m.theta, colour="M"), size= .5) +
geom_line(aes(y=x.s.theta, colour="S"),size= .5) +
scale_x_continuous(breaks=c
(0,10000000,20000000,30000000,40000000,50000000), labels=c("0", "10",
"20","30", "40", "50")) +
scale_colour_discrete("Species") +
scale_colour_brewer(palette="Set1") +
opts(axis.text.x = theme_text(colour = "black", vjust=1))+
opts(axis.text.y = theme_text(colour = "black", hjust=1)) +
theme_bw()

and b, and c are similar

print(a, vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
print(b, vp = viewport(layout.pos.row = 1, layout.pos.col = 2))

print(c, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
dev.off()

Many thanks, again.
Squid.

baptiste

unread,
Aug 31, 2009, 8:26:29 AM8/31/09
to ggplot2
Hi,


Inspired by this page:
http://wiki.r-project.org/rwiki/doku.php?id=tips:graphics-ggplot2:sharelegend

a + opts(legend.position = "none")

should work (but I've just screwed up my R installation so I haven't
tested)


HTH,

baptiste

Jorge Ahumada

unread,
Mar 28, 2013, 10:04:01 AM3/28/13
to ggp...@googlegroups.com, bapt...@googlemail.com
opts() is now deprecated so using theme() instead.. 

Tom

unread,
Jun 13, 2013, 1:58:32 PM6/13/13
to ggp...@googlegroups.com, bapt...@googlemail.com
I would like to completely remove the legend, as the o.p. did, but theme() doesn't seem to be working for me here.
 
When I call ggplot with a + theme_grey(legend.position = "none") option, which seems to be right by my reading of the documentation, I get an error:
 
Error in theme_grey(base_size = 8, legend.position = "right") : 
  unused argument (legend.position = "right")
 
Code to produce this error:
 
my.alpha.fwer <- data.frame(alpha <- rep(c(0.025, 0.05, 0.10), each = 10), n <- rep(seq(from=1, to=10), times=3))
my.alpha.fwer$fwer <- with(my.alpha.fwer, (1-(1-alpha)^(n*(n-1)/2)))
colnames(my.alpha.fwer) <- c("alpha", "n", "fwer")
my.alpha.fwer$alpha <- as.factor(my.alpha.fwer$alpha)
ggplot(aes(x = n,y = fwer,colour = alpha, na.rm = TRUE), data=my.alpha.fwer) +
  geom_line() +
  facet_grid(facets = alpha ~ .) +
  scale_x_continuous(name = 'number of comparisons, n', limits = c(2,7),breaks = c(2,4,6,8),labels = c("2","4","6","8")) +
  scale_y_continuous(name = 'Family-Wise Error Rate', limits = c(0.05, 0.5), breaks = c(0.05, 0.5, 0.95), labels = c("0.05","0.5","0.95")) +
  theme_gray(base_size = 8.0, legend.position="right")
 
Thanks for your help.
 
- Tom

Ito, Kaori (Groton)

unread,
Jun 13, 2013, 2:09:59 PM6/13/13
to Tom, ggp...@googlegroups.com, bapt...@googlemail.com

If you just want to “completely remove” the legend, use:

theme(legend.position="none")

…instead of  theme_gray(base_size = 8.0, legend.position="right").

?

--
--
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
 
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages