changing legend label for barplot

2,489 views
Skip to first unread message

Andrew Redd

unread,
Jan 19, 2011, 6:39:34 PM1/19/11
to ggp...@googlegroups.com
using the example on the website as a reference.

library(ggplot2)
qplot(factor(cyl), data=mtcars, geom="bar", fill=factor(cyl))

How do I change the label of the legend?

Thanks,
Andrew

David Kahle

unread,
Jan 19, 2011, 7:23:43 PM1/19/11
to Andrew Redd, ggp...@googlegroups.com
qplot(factor(cyl), data = mtcars, geom = 'bar', fill = factor(cyl)) +
  scale_fill_discrete('label here')

Cheers
david.

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Scott Chamberlain

unread,
Jan 19, 2011, 7:27:06 PM1/19/11
to David Kahle, Andrew Redd, ggp...@googlegroups.com
Or:

ggplot(mtcars, aes(factor(cyl), fill=factor(cyl))) + geom_bar() + labs(fill="label here")

Andrew Redd

unread,
Jan 19, 2011, 11:03:33 PM1/19/11
to Scott Chamberlain, David Kahle, ggp...@googlegroups.com
Thank you.  Are these documented somewhere?  I could not find it.
-Andrew

David Kahle

unread,
Jan 20, 2011, 1:39:20 AM1/20/11
to Scott Chamberlain, Andrew Redd, ggp...@googlegroups.com
There is documentation for labs, if that's what you're looking for.  Just ?labs it.  Otherwise, the scales are also uniform with respect to legend naming conventions, in the sense that scale_[aesthetic] always (as I am thinking now) takes as a first argument the title of the legend which it will generate (if indeed it does generate one).  Check Hadley's webpage at http://had.co.nz/ggplot2/ for more info.

Hope it helps!
david.


On Jan 19, 2011, at 10:26 PM, Scott Chamberlain wrote:

I don't know of any documentation...

Scott
Reply all
Reply to author
Forward
0 new messages