DATA MINING
Desktop Survival Guide by Graham Williams |
|||||
The legend function is used to add a legend to a plot. A specific coordinate can be given as the first two arguments, or else a symbolic location, such as topleft and center, can be given. The pch option specifies a plotting symbol, and the first 25 (1:25) are shown on the plot below. Other symbols are available in the 32:255 range. The lty is used to specify line types. The col is used to specify colours.
plot(1:10, rep(7.5,10), ylab="", ylim=c(1,10), xlim=c(1,10), pch=1:10, col=1:10) points(1:10, rep(7,10), pch=11:20, col=11:20) points(1:5, rep(6.5,5), pch=21:25, col=21:25) legend("topleft", "topleft pch 1", pch=1) legend("top" , "top pch 2", pch=2) legend("topright", "topright pch 3", pch=3) legend("left", "left pch 6", pch=6) legend("center", "center pch 7", pch=7) legend("right", "right pch 8", pch=8) legend("bottomleft", "bottomleft pch 10", pch=10) legend("bottom", "bottom pch 11", pch=11) legend("bottomright", "bottomright pch 12", pch=12) legend <- c("topleft pch 4", "inset pch 5") legend("topleft", legend, inset=c(0.1, 0.1), pch=c(4,5)) legend(2, 3, legend="point (2,3) pch 9", title="title", pch=9) plen <- length(palette()) legend(5.5, 4.5, palette(), lty=1:plen, col=1:plen, ncol=2) |