# [R] legend at fixed distance form the bottom

Christophe Genolini cgenolin at u-paris10.fr
Sat Dec 6 17:11:03 CET 2008

```Thanks to answering me Gabor

I am not sur I understand : I had your line to my graph. Then I resize
my graph but the legend is still moving. In "inset = c(0,1.1)",
1.1 means "110% of the y length of the plot region". So when the plot
region change, the distance between the legend and the top axe is sitll
110%, that means that the distance between the legend and the bottom axe
is 10%...

Christophe

> inset= is measured from the margin so the trick is to inset it relative to the
> top even if you want it at the bottom:
>
> legend("top", pch = unique(listSymboles), legend = c("ane", "cheval",
> "poney", "mule"),
>   inset = c(0,1.1), horiz = TRUE, xpd = NA)
>
> On Fri, Dec 5, 2008 at 8:39 AM, Christophe Genolini
> <cgenolin at u-paris10.fr> wrote:
>
>> Hi the list
>>
>> I would like to add a legend under a graph but at a fixed distance from the
>> graphe. Is it possible ?
>> More precisely, here is my code :
>>
>> --- 8< ----
>> symboles <- c(3,4,5,6)
>> dn <- rbind(matrix(rnorm(20),,5),matrix(rnorm(20,2),,5))
>> listSymboles <- rep(symboles,each=2)
>> matplot(t(dn),pch=listSymboles,type="b")
>> legend("bottom", pch = unique(listSymboles), legend = c("ane", "cheval",
>> "poney", "mule"), inset = c(0,-0.175), horiz = TRUE, xpd = NA)
>> --- 8< ----
>>
>> But when I change the size of the graph, the legend is misplaced.
>>
>> Instead, I try to put some text in xlab, but I do not know how to get the +,
>> x , V and other symbol.
>> Does anyone got a solution ?
>>
>> Thanks a lot.
>>
>> Christophe
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help