[R] Legend based on levels of a variable

windmagics_lsl shfu_lsl at 163.com
Fri Apr 6 09:37:36 CEST 2012


I think there may 3 legends should be added in your plot
the argument col, pch and pt.cex should be in the same length with legend,
but the objects col, pch
 and cex you defined former have 16*3 length. I guess the follow codes may
work

col <- rep(c("blue", "red", "darkgreen"), c(16, 16, 16)) 
## Choose different size of points 
cex <- rep(c(1, 1.2, 1), c(16, 16, 16)) 
## Choose the form of the points (square, circle, triangle and 
diamond-shaped 
pch <- rep(c(15, 16, 17), c(16, 16, 16)) 

plot(axis1, axis2, main="My plot", xlab="Axis 1", ylab="Axis 2", 
 col=c(Category, col), pch=pch, cex=cex) 
legend(4, 12.5, c("NorthAmerica", "SouthAmerica", "Asia"), col =
unique(col), 
       pch = unique(pch), pt.cex = unique(cex), title = "Region") 

--
View this message in context: http://r.789695.n4.nabble.com/Legend-based-on-levels-of-a-variable-tp4536796p4536868.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list