[R] Size of the legend

David Winsemius dwinsemius at comcast.net
Tue Sep 21 19:53:18 CEST 2010


On Sep 21, 2010, at 1:28 PM, Mestat 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")

Learn to use spaces between arguments and indent meaningfully!!

Best I could do with base graphics. Lattice would give you more  
control I suspect:

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=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")
                             ),
                   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")

Need to avoid embedding carriage returns in the expression arguments  
since they get carried through to the plot ((and ISTR that \n does not.)

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list