[R] legend position help

Jinsong Zhao jszhao at yeah.net
Thu Aug 16 04:05:06 CEST 2012


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.
>
>
>



More information about the R-help mailing list