[R] The "inset" argument in legend().

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Sat Oct 30 02:29:06 CEST 2021


On 29/10/2021 8:19 p.m., Rolf Turner wrote:
> 
> I cannot get the "inset" argument in legend() to produce the results
> that I want.  It seems to me that when the legend position argument is
> set to "bottom" then only the second (y-component) entry of "inset"
> has any effect, and when the position argument is "left" then only
> the first (x-component)  entry of "inset" has any effect.
> 
> I have attached a file "legDemo.txt" which can be sourced to
> demonstrate the behaviour that I am encountering.
> 
> I thought that maybe if one uses "inset" then one should not specify
> the legend position, but that causes an error to be thrown.
> 
> I want to have a near the bottom of the plot and to adjust its
> position, in the horizontal direction by means of "inset", but nothing
> that I try has the desired effect.
> 
> Am I misunderstanding something?  Or is there perhaps a bug in
> legend()?

I think it is working as designed.  If you say "bottom", the y distance 
will be ignored:  it would only be considered for things that are placed 
relative to the vertical margins, i.e. bottomright, bottomleft, etc. 
The design doesn't say what an "inset" of the middle value would be.

To move things slightly away from the middle, I think you've got to look 
at par("usr") and place it yourself, giving numerical values for x and y.

Duncan Murdoch



More information about the R-help mailing list