Remove the legend

12 views
Skip to first unread message

Vikas Rawal

unread,
Feb 9, 2009, 4:20:53 AM2/9/09
to ggplot2

Why does the following plot produce a colour legend on the right despite
my saying legend.position="none"?

ggplot(c)+opts(legend.postition="none")+geom_smooth(aes(x=Operational_holding,y=Crop_production),method="lm")+geom_smooth(aes(x=Operational_holding,y=Crop_production+Animal_resources,colour="red"),method="lm")

Will be grateful if anyone could explain how to turn off the legend.

Vikas

hadley wickham

unread,
Feb 9, 2009, 8:33:48 AM2/9/09
to Vikas Rawal, ggplot2
Hi Vikas,

It's hard to say without a reproducible example. The following code
certainly works for me.
qplot(mpg, wt, data=mtcars, colour=factor(vs)) + opts(legend.position="none")

However, in your case you probably should just do:

geom_smooth(aes(x=Operational_holding,y=Crop_production+Animal_resources),method="lm",
colour="red")

(i.e. move colour out of the aes call) so you don't get a legend in
the first place.

Hadley
--
http://had.co.nz/
Reply all
Reply to author
Forward
0 new messages