nzcoops
unread,Jul 18, 2012, 12:38:05 AM7/18/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ggplo...@googlegroups.com
Okay, to expand on this, having looked in guides via joran on SO.
p <- ggplot(mtcars, aes(x=wt, y=mpg, colour=factor(cyl))) + geom_line()
p + opts(legend.title=theme_text(size = 15))
# great that bumped the font size up, the 'original/old way'
# now use the new guides options
p + guides(colour = guide_legend(title.theme = theme_text(size = 8)))
p + guides(colour = guide_legend(title.theme = theme_text(size = 8), title.position="left"))
p + guides(colour = guide_legend(title.theme = theme_text(size = 8), title.position="left", title.vjust=2))
p + guides(colour = guide_legend(title.theme = theme_text(size = 8), title.position="left", title.vjust=2, title.hjust=1))
# so we can change the font size, move it to one size, change vertical alignment but not horiztonal?
# but what if it's on top?
p + guides(colour = guide_legend(title.theme = theme_text(size = 8)))
p + guides(colour = guide_legend(title.theme = theme_text(size = 8), title.hjust=1))
p + guides(colour = guide_legend(title.theme = theme_text(size = 8), title.hjust=1, title.vjust=2))
# can change size but not alignment
# what about nrow
p + guides(colour = guide_legend(nrow=2,title.theme = theme_text(size = 8)))
p + guides(colour = guide_legend(nrow=2,title.theme = theme_text(size = 8), title.hjust=1))
p + guides(colour = guide_legend(nrow=2,title.theme = theme_text(size = 8), title.hjust=1, title.vjust=2))
# so when it's on top we can adjust the horizontal but not the vertical alignment
From this I conclude that we can't tweak vjust when the title is on top, can't tweak hjust when it's the on the side and can only tweak hjust on the top when it's forced wider with nrow. To me this isn't optimal functionality and is more restrictive than what we used to have? Or is there something I'm missing.
The way I came across this was through tweaking a graph for publication, in a tight space (2.6" wide output), and needing to move the legend title just a fraction. I wrote the theme for this particular graph I'm doing a few months ago, then noticed it wasn't doing now what it did then, then noticed the move to 'guides' via joran @SO, then wound up here(/ in this position).
Cheers