plotting raster data in R: adjusting the labels and colors of a classified raster

[This article was first published on geo-affine » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Thank’s to Andrej who wrote this comment:
“Is it possible to to color the resulting 12 clusters within your original image to get a feel for visual separation?”
You can do so:

map in R with labels

map in R with labels (click to enlarge)

arg <- list(at=seq(1,12,1), labels=c("none","none","vegetation","none","none","vegetation","none","none","none","none","water","none")) #these are the class names
color=c("black","black","green","black","black","green","black","black","black","black","blue","black") #and color representation
plot(G, col=color, axis.arg=arg)

But how to get values at a location? You will need these values to determine whether the defined class is representing a water body or a forest. Use the layerstack in a second plot as reference. But use this line to determine the class number at a chosen location:

extract(G, data.frame(locator()))

To leave a comment for the author, please follow the link and comment on their blog: geo-affine » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)