[R] legend position help

Greg Snow 538280 at gmail.com
Thu Aug 16 18:03:55 CEST 2012


A quick hack to give you space between the line and point (if you only
used solid lines) is to specify lty='ff' to the legend function.

If you want more control then look at setting trace=TRUE and
plot=FALSE and looking at the printed outcome and the return value
from legend.  This does not plot the legend, but gives you the
information that you can use to create the legend yourself (and could
therefore move the pieces that you want moved).

On Wed, Aug 15, 2012 at 8:05 PM, Jinsong Zhao <jszhao at yeah.net> wrote:
> On 2012-08-16 0:22, Greg Snow wrote:
>>
>> You can use the grconvertY function to find the position in the
>> current user coordinates that corresponds to the top of the device
>> area (instead of using locator).
>>
>
> Thank you very much. grconvertX() and grconvertY() work very well.
>
>
>> Look at the "merge" argument to the legend  function.
>
>
> I gave "merge = FALSE" in the command. It gave the result like:
> ---o
> However, I hope to get something like:
> --- o
> or
> o --- (I prefer to this one)
>
> There should be a space between the point and line.
>
> Thanks again.
>
> Regards,
> Jinsong
>
>
>>
>> On Wed, Aug 15, 2012 at 10:04 AM, Jinsong Zhao <jszhao at yeah.net> wrote:
>>>
>>> Hi there,
>>>
>>> I draw a multiple figure in one plot, like the following:
>>>
>>> par(mfcol=c(1,5),mar=c(4,4,0,0)+0.2, oma=c(0,0,3,0))
>>> plot(1:10, type = "b")
>>> plot(1:10, type = "b")
>>> plot(1:10, type = "b")
>>> plot(1:10, type = "b")
>>> plot(1:10, type = "b")
>>>
>>> Now, I hope to plot the legend like the following:
>>>
>>> legend("top", legend=c("Example"), pch = 21, lty = 1, merge = FALSE,
>>> horiz =
>>> TRUE, bty="n", xpd = NA)
>>>
>>> There were two problems:
>>>
>>> 1) the legend is put inside the fifth figure instead of the top center of
>>> the whole plot, i.e., the center of the outer top margin.
>>>
>>> Now, I use a stupid solution, I replace "top" in the above command with
>>> locator(1). However, using this solution, the plot have to be in an
>>> interactive mode, and the position is not accuracy.
>>>
>>> 2) the point is connected with the line in the legend. I hope there is a
>>> space between the two symbols, like --- o instead of  ---o. If possible,
>>> put
>>> the point before the line, like o ----. Unfortunately, I don't find any
>>> way
>>> to do that.
>>>
>>> Any suggestion will be greatly appreciated.
>>>
>>> Regards,
>>> Jinsong
>>>
>>> ______________________________________________
>>> 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.
>>
>>
>>
>>
>



-- 
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com



More information about the R-help mailing list