Re: [R] Patch for legend.position={left,top,bottom} in ggplot2

From: Felipe Carrillo <mazatlanmexico_at_yahoo.com>
Date: Thu, 10 Jun 2010 07:30:44 -0700 (PDT)

Hi:
I downloaded the patch, how do I incorporate it to my current version of ggplot2?  
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA

On Thursday, June 10, 2010, Karsten Loesing <> ymailto="mailto:karsten.loesing_at_gmx.net"
> href="mailto:karsten.loesing_at_gmx.net">karsten.loesing_at_gmx.net>
> wrote:
> Hi everyone,
>
> here's the same patch as a new
> branch on GitHub.
>

>  http://github.com/kloesing/ggplot2/commit/a25e4fbfa4017ed1
>
>
> Best,
> --Karsten
>
>
> On 6/7/10 3:39 PM, Karsten
> Loesing wrote:
>> Hi Hadley and everyone,
>>
>>
> here's a patch for ggplot2 that fixes the behavior of
>>
> opts(legend.position={left,top,bottom}). If you try the following
> code
>> in an unmodified ggplot2
>>
>> options(warn =
> -1)
>> suppressPackageStartupMessages(library("ggplot2"))
>>
> data <- data.frame(
>>     x = c(1, 2, 3, 4, 5, 6),
>>    
> y = c(2, 3, 4, 3, 4, 5),
>>     colour = c(TRUE, TRUE, TRUE, FALSE,
> FALSE, FALSE))
>> ggplot(data, aes(x = x, y = y, colour = colour))
> +
>>     geom_line() + opts(title = "title", legend.position =
> "right")
>> ggplot(data, aes(x = x, y = y, colour = colour))
> +
>>     geom_line() + opts(title = "title", legend.position =
> "left")
>> ggplot(data, aes(x = x, y = y, colour = colour))
> +
>>     geom_line() + opts(title = "title", legend.position =
> "top")
>> ggplot(data, aes(x = x, y = y, colour = colour))
> +
>>     geom_line() + opts(title = "title", legend.position =
> "bottom")
>>
>> you'll see that plots 2 to 4 are
> broken.
>>
>> I think I located the bug in
> surround_viewports() where the graphical
>> elements are placed into
> the grid. If we increment all rows and columns
>> of the graphical
> elements for positions "left", "top", and "bottom" by
>> 1, those
> graphs look sane again. I assume that a new first row and
>> column
> were added at some point in the development, but only the
>> parameters
> for the default position "right" were adjusted. Here's the
> patch:
>>
>>
>> --- ggplot2-orig2     2010-06-07
> 13:14:35.000000000 +0200
>> +++ ggplot2   2010-06-07 15:22:33.000000000
> +0200
>> @@ -7003,27 +7003,27 @@
>>      )
>>    }
> else if (position == "left") {
>>      viewports <-
> vpList(
>> -      vp("panels", 2, 3),
>> -    
>  vp("legend_box", 2, 1),
>> -      vp("ylabel", 2, 2),
>> -  
>    vp("xlabel", 3, 3),
>> -      vp("title", 1, 3)
>> +    
>  vp("panels", 3, 4),
>> +      vp("legend_box", 3, 2),
>> +  
>    vp("ylabel", 3, 3),
>> +      vp("xlabel", 4, 4),
>> +    
>  vp("title", 2, 4)
>>      )
>>    } else if (position ==
> "top") {
>>      viewports <- vpList(
>> -    
>  vp("panels", 3, 2),
>> -      vp("legend_box", 2, 2),
>> -  
>    vp("ylabel", 3, 1),
>> -      vp("xlabel", 4, 2),
>> -    
>  vp("title", 1, 2)
>> +      vp("panels", 4, 3),
>> +    
>  vp("legend_box", 3, 3),
>> +      vp("ylabel", 4, 2),
>> +  
>    vp("xlabel", 5, 3),
>> +      vp("title", 2, 3)
>>    
>  )
>>    } else if (position == "bottom") {
>>      viewports
> <- vpList(
>> -      vp("panels", 2, 2),
>> -    
>  vp("legend_box", 4, 2),
>> -      vp("ylabel", 2, 1),
>> -  
>    vp("xlabel", 3, 2),
>> -      vp("title", 1, 2)
>> +    
>  vp("panels", 3, 3),
>> +      vp("legend_box", 5, 3),
>> +  
>    vp("ylabel", 3, 2),
>> +      vp("xlabel", 4, 3),
>> +    
>  vp("title", 2, 3)
>>      )
>>    } else {
>>    
>  viewports <- vpList(
>>
>>
>> Best,
>>
> --Karsten
>>
>
>

-- 
Assistant Professor / 

> Dobelman Family Junior Chair
Department of Statistics / Rice
> University
http://had.co.nz/ ______________________________________________
> ymailto="mailto:R-help_at_r-project.org"
> href="mailto:R-help_at_r-project.org">R-help_at_r-project.org mailing list
> href="https://stat.ethz.ch/mailman/listinfo/r-help" target=_blank
> >https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting
> guide http://www.R-project.org/posting-guide.html
and provide commented,
> minimal, self-contained, reproducible code.
______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Received on Thu 10 Jun 2010 - 14:33:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 10 Jun 2010 - 15:00:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive