Hi:

It is not good graphics for a legend to overlap data points, so let's see
how one can get said legend away from the data.

One approach in base graphics is to extend the y-axis limits and to place
the legend in the open area. It would probably be better to split the legend
into two halves and place separate legends on both ends, but I'll let you do
that as R homework. The following is a small modification of David's yeoman
work; the dotted line isn't really necessary, but it provides a visual
separation between the plot and the legend. (And, to echo David's remarks
about the code blob, I hope this is easier to read and understand...)

x<-runif(100)
y<-runif(100)
color<-c(rep(1,15),rep(2,20),rep(3,15),rep(4,10),rep(5,10),rep(6,15),rep(7,10),rep(8,5))
# Combine vectors into a data frame and remove original variables from the
workspace
mydf <- data.frame(x = x, y = y, color = color)
rm(x, y, color)

# Legend elements
mylegend <- expression(scriptstyle("All 3 outliers"),
                            scriptstyle("Presence of 2 outliers (6,263 and
6,720)"),
                            scriptstyle("Presence of 2 outliers (3,471 and
6,720)"),
                            scriptstyle("Presence of 2 outliers (3,471 and
6,263)"),
                            scriptstyle("Presence of outlier 6,720"),
                            scriptstyle("Presence of outlier 6,263"),
                            scriptstyle("Presence of outlier 3,471"),
                            scriptstyle("No outlier") )
mypch <- c(22,3,3,3,19,19,19,23)
mycol <- c("black","blue","green","red","red","green","blue","black")

plot(y ~ x, data = mydf, col = color, pch = mypch[color], ylim = c(0, 1.5),
            xlab='Sample Mean', ylab='Bootstrap Variance Estimators', main =
'')
legend('topleft', leg = mylegend, col = mycol, pch = mypch,
                  lty = c(1, 1), xjust=0, yjust=0, bty="n")
abline(1.02, 0, lty = 'dotted')

Since I have to contribute something novel, here's a lattice version that
David suggested would make a good alternative, and I believe it does, but
that's my opinion - judge it for yourself.

library(lattice)
# Reconstitute the original legend text items
mylegend2 <- c("All 3 outliers",
               "Presence of 2 outliers (6,263 and 6,720) ",
               "Presence of 2 outliers (3,471 and 6,720) ",
               "Presence of 2 outliers (3,471 and 6,263) ",
               "Presence of outlier 6,720",
               "Presence of outlier 6,263",
               "Presence of outlier 3,471",
               "No outlier" )
# Generate code for a legend key
mykey <- list(space = 'top',
              columns = 2,
              text = list(mylegend, cex = 0.8),
              points = list(pch = mypch, col = mycol, cex = 0.8))

xyplot(y ~ x, data = mydf, col = mydf$color, pch = mypch[mydf$color],
              xlab='Sample Mean', ylab='Bootstrap Variance Estimators', main
= '',
              key = mykey)

HTH,
Dennis


On Tue, Sep 21, 2010 at 10:28 AM, Mestat <mestat@pop.com.br> wrote:

>
> Hi Denis,
> Check it out my code... This is not my real data...
> I would like to manage the size of the legend... Set the legend smaller
> than
> it is, because on my real data, the legend is over the values...
> Thanks for the help...
>
> x<-runif(100)
> y<-runif(100)
>
> color<-c(rep(1,15),rep(2,20),rep(3,15),rep(4,10),rep(5,10),rep(6,15),rep(7,10),rep(8,5))
>
>
> plot(x,y,col=c("black","blue","green","red","red","green","blue","black")[color],pch=c(22,3,3,3,19,19,19,23)[color],main='
> ',xlab='Sample Mean',ylab='Bootstrap Variance Estimators')
> legend("topleft", legend=c("All 3 outliers","Presence of 2 outliers (6,263
> and 6,720)","Presence of 2 outliers (3,471 and 6,720)","Presence of 2
> outliers (3,471 and 6,263)","Presence of outlier 6,720","Presence of
> outlier
> 6,263","Presence of outlier 3,471","No outlier"), col =
> c("black","blue","green","red","red","green","blue","black"), pch =
> c(23,19,19,19,3,3,3,22), lty=c(1,1), xjust=0, yjust=0, bty="n")
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Size-of-the-legend-tp2547601p2549063.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>

	[[alternative HTML version deleted]]

