Bug 14719 - Wish: add option to change font in legend()
Wish: add option to change font in legend()
Status: RESOLVED FIXED
Product: R
Classification: Unclassified
Component: Graphics
R 2.14.0
All All
: P5 enhancement
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-11-02 12:38 UTC by Timothy Paine
Modified: 2014-02-16 11:43 UTC (History)
2 users (show)

See Also:


Attachments
modified legend() function (8.92 KB, text/plain)
2011-11-02 12:38 UTC, Timothy Paine
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Timothy Paine 2011-11-02 12:38:47 UTC
Created attachment 1243 [details]
modified legend() function

Dear all, 
Occasionally it would be nice to change the font of the text that appears in a legend (for me, eg, scientific names). Currently, legend() does not accept a 'font =' argument. It appears a simple matter to implement the ability to change fonts of a legend. In the attachment, I modified legend() to do so. legend() could retain its current default behavior by using the default argument "text.font = 1". By modifying the call to strwidth() within legend, we can prevent the text from overflowing the bounding box of the legend. 

Best wishes, 
Tim Paine
Comment 1 Martin Maechler 2011-11-02 14:30:40 UTC
(In reply to comment #1)
> 
> On 02.11.2011 12:38, r-bugs@r-project.org wrote:
> > https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14719
> >
> >             Summary: Wish: add option to change font in legend()
> >             Product: R
> >             Version: R 2.14.0
> >            Platform: All
> >          OS/Version: All
> >              Status: NEW
> >            Severity: enhancement
> >            Priority: P5
> >           Component: Graphics
> >          AssignedTo: R-core@R-project.org
> >          ReportedBy: timothy.paine@ieu.uzh.ch
> >     Estimated Hours: 0.0
> >
> >
> > Created an attachment (id=1243) [details]
> >   -->  (https://bugs.r-project.org/bugzilla3/attachment.cgi?id=1243)
> > modified legend() function
> >
> > Dear all,
> > Occasionally it would be nice to change the font of the text that appears in a
> > legend (for me, eg, scientific names). Currently, legend() does not accept a
> > 'font =' argument. It appears a simple matter to implement the ability to
> > change fonts of a legend. In the attachment, I modified legend() to do so.
> > legend() could retain its current default behavior by using the default
> > argument "text.font = 1". By modifying the call to strwidth() within legend, we
> > can prevent the text from overflowing the bounding box of the legend.
> >
> > Best wishes,
> > Tim Paine
> >
> 
> I think the overhead compared to the simple
> 
>   plot(1)
>   par(font=4)
>   legend("topleft", legend="Hello World")
> 
> is not worth the efforts and complication of things. I will close this 
> one shortly unless I see objections or good reasons for even more 
> arguments to legend() - (move discussion to R-devel please, if 
> discussion is required).
> 
> Best,
> Uwe Ligges

Actually, I'd like to have a look at the proposition, and see if the complication can be kept low.
Having to use par() {and reset it to it's previous value} 
seems a bit ugly to me.

So consider this as "assigned to Martin"  (if jitterbug does not say so: I seem to not achieve that on the web page).

Martin Maechler
Comment 2 Timothy Paine 2011-11-02 14:49:35 UTC
Dear Martin and Uwe, 
I agree that Uwe's solution using par() is simple. But I have to admit that I had never considered that option, despite a pretty solid command of R. I would guess that other users would not alight on that solution either. I think that including the ability to change fonts from within legend() would be more self-evident.

Thank you for your quick replies and careful consideration.

best-
tim
Comment 3 Uwe Ligges 2011-11-02 16:52:08 UTC

On 02.11.2011 12:38, r-bugs@r-project.org wrote:
> https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14719
>
>             Summary: Wish: add option to change font in legend()
>             Product: R
>             Version: R 2.14.0
>            Platform: All
>          OS/Version: All
>              Status: NEW
>            Severity: enhancement
>            Priority: P5
>           Component: Graphics
>          AssignedTo: R-core@R-project.org
>          ReportedBy: timothy.paine@ieu.uzh.ch
>     Estimated Hours: 0.0
>
>
> Created an attachment (id=1243)
>   -->  (https://bugs.r-project.org/bugzilla3/attachment.cgi?id=1243)
> modified legend() function
>
> Dear all,
> Occasionally it would be nice to change the font of the text that appears in a
> legend (for me, eg, scientific names). Currently, legend() does not accept a
> 'font =' argument. It appears a simple matter to implement the ability to
> change fonts of a legend. In the attachment, I modified legend() to do so.
> legend() could retain its current default behavior by using the default
> argument "text.font = 1". By modifying the call to strwidth() within legend, we
> can prevent the text from overflowing the bounding box of the legend.
>
> Best wishes,
> Tim Paine
>


I think the overhead compared to the simple

  plot(1)
  par(font=4)
  legend("topleft", legend="Hello World")

is not worth the efforts and complication of things. I will close this 
one shortly unless I see objections or good reasons for even more 
arguments to legend() - (move discussion to R-devel please, if 
discussion is required).

Best,
Uwe Ligges


Comment 4 Martin Maechler 2011-11-10 14:40:10 UTC
implemented (default = NULL, not '1')  for R-devel -- 2.15.0 to be
Comment 5 Jackie Rosen 2014-02-16 11:43:03 UTC
(spam comment removed)