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

August 2, 2012
By

(This article was first published on geo-affine » R, and kindly contributed to R-bloggers)

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 his blog: geo-affine » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , , , , , , , ,

Comments are closed.