data(loaloa)
plot(ltLoa, breaks = c(-0.5, levels(ltLoa)[[1]]$ID+0.5),
col=levels(ltLoa)[[1]]$rgb, legend=FALSE)
forLegend = as.numeric(names(sort(table(values(ltLoa)),decreasing=TRUE)))[1:4]
forLegend = match(levels(ltLoa)[[1]]$ID , forLegend, nomatch = 0) > 0
legend("topright", fill=levels(ltLoa)[[1]][forLegend,"rgb"],
legend=
substr(as.character(levels(ltLoa)[[1]][forLegend,"CLASSNAMES"]),1,24))
points(loaloa)
Run the code above in your browser using DataLab