Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adjust line size in geom_line without obtaining another (useless) legend?

Tags:

r

ggplot2

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!

like image 598
Matt Bannert Avatar asked Jul 30 '10 23:07

Matt Bannert


1 Answers

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)
like image 122
JoFrhwld Avatar answered Oct 23 '22 04:10

JoFrhwld