[R] problem with legend

Jim Lemon jim at bitwrit.com.au
Fri Dec 12 10:51:52 CET 2008


valeria pedrina wrote:
> hi all,
> I want to do a plot and put the legend on the left of y axis this is my
> code:
>
> x<-seq(1980,2005,1)
>
> plot(x,tfa_ita,type="l",col=1,xlim=c(1979,2005),ylim=c(0.2,1.7),xlab="",ylab="",main="Totale
> Attivita` Finanziarie")
> lines(x,tfa_spa,type="l",col=2)
> lines(x,tfa_aus,type="l",col=3)
> lines(x,tfa_uk,type="l",col=4)
> lines(x,tfa_ger,type="l",col=5)
> lines(x,tfa_usa,type="l",col=1,lty=4)
> lines(x,tfa_jap,type="l",col=2,lty=4)
> lines(x,tfa_can,type="l",col=3,lty=4)
> lines(x,tfa_fra,type="l",col=4,lty=4)
>
> legend(locator[1],c("ita","spa","aus","uk","ger","usa","jap","can","fra"),col=c(1,2,3,4,5,1,2,3,4),lty=c(1,1,1,1,1,4,4,4,4))
>
>
> when I touch the graphics to put the legend, R puts it on my lines and not
> on the left of y axis
>   
Hi Valeria,
The legend command should start with locator(1) using parentheses and 
not square brackets. This is probably just a typo in your email, or you 
wouldn't have gotten a legend at all. By default, the legend is placed 
with the upper left corner at the user coordinates specified. If you 
want to place it partly outside the plot, use par(xpd=TRUE) and 
box.col=(par"bg").

Jim



More information about the R-help mailing list