I am getting some funny behaviour for colors in a legend I am adding to a plot. The plot is fairly hard to reproduce, but the behaviour can be reproduced from the example below:
mod3.cor.spo = 10
mod2.cor.spo = 10
mod1.cor.spo = 10
mod1.MBE.spo = 10
mod2.MBE.spo = 10
mod3.MBE.spo = 10
plot(1:10)
legend("bottomleft",
c(paste("r = ", sprintf("%1.3g", mod1.cor.spo)," MBE = ", sprintf("%1.3g", mod1.MBE.spo), "%", sep=""),
paste("r = ",sprintf("%1.3g", mod2.cor.spo)," MBE = ", sprintf("%1.3g", mod2.MBE.spo), "%", sep=""),
paste("r = ",sprintf("%1.3g", mod3.cor.spo)," MBE = ", sprintf("%1.3g", mod3.MBE.spo), "%", sep="")),
cex=0.6, col=c("red","blue","orange"), bty="n" )
Hopefully if you try this you should see that the text in the legend is all printed out black. What I expected (and wanted) to happen was that the legend (which prints out in three rows) would have the first row of text colored red, second row blue and the bottom row orange.
Is there something I am doing wrong here? Is it down to the use of combining lots of character strings?
You have to write text.col=c("red","blue","orange")
instead of col=c("red","blue","orange")
see ?legend