tags:

views:

50

answers:

1

Dear all,

i´d like to adjust the size of my lines (both of them), because i feel they're too skinny. The following code does so, but creates a legend for size, which is useless since size has no variable that can be mapped to it.

qplot(date,value,data=graph1,geom="line",colour=variable,xlab="",ylab="",size=1)
+ scale_y_continuous(limits = c(-0.3,0.3)) + opts(aspect.ratio = 2/(1+sqrt(5))) 
+ scale_colour_manual("Variable",c(Line1="red",Line2="blue")) 
+ opts(legend.size="none")

My plot consists of two lines representing a time series of two different variables over the same time span. The variable is mapped to color. If I try to influence the size of the line, qplot always tries to map "size" to another parameter and display another legend.

I also followed this discussion, that ended with Hadley telling the others that removing a part of the legend is not implemented yet. I understand that adding another paramater to the mix implies the need of a legend for this parameter. Maybe I am using the wrong command to influence line size just for visual reasons.

Thx for any suggestions!

+3  A: 

I believe in qplot() all aesthetic settings are interpreted as being within aes(). If you don't want your size setting to appear in the legend, wrap the value with I() for as-is.

qplot(date, value,data=graph1,
      geom="line",
      colour=variable,xlab="",
      ylab="",
      size= I(1))+
   scale_y_continuous(limits = c(-0.3,0.3))+
   scale_colour_manual("Variable",c(Line1="red",Line2="blue"))+ 
   opts(legend.size="none",
        aspect.ratio = 2/(1+sqrt(5)))

Now there shouldn't be a size legend.

Another thing to note is that eliminating an aesthetic scale from the legend is now possible. If, for instance, you wanted to remove the size scale a harder way, you could do

last_plot() + scale_size(legend = F)
JoFrhwld
Thx for providing even two working solutions. Just setting size=I(1) worked without any other argument. Using the + scale_size(legend=F) worked as well on its own. Future Googlers: note that the + opts(legend.size="none") (which I tried would have considered the most intuitive solution – particularly after reading the chapter legends and axes from Hadley's Book) is unfortunately not working.
ran2
You want `opts(legend.position = "none")`.
hadley
@hadley, no not here. As far as I understand, that would hide ALL legends. In my example, the standard color legend is just perfect.
ran2