I simply download a map from here http://neo.sci.gsfc.nasa.gov/view.php?datasetId=MCD12C1_T1. this map is a tiff file.
mapd <- raster("C:\\MCD12C1_T1_2011-01-01_rgb_1440x720.TIFF")
plot(mapd)
you can see there is no legend at all, any help
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI simply download a map from here http://neo.sci.gsfc.nasa.gov/view.php?datasetId=MCD12C1_T1. this map is a tiff file.
mapd <- raster("C:\\MCD12C1_T1_2011-01-01_rgb_1440x720.TIFF")
plot(mapd)
you can see there is no legend at all, any help
The colors are stored with the TIFF file, but either the legend class names are not in there or else they are not read by raster
. Therefore you will have to manually copy the legend names from the Web site and manually create an informative legend, but you can automatically display the codes for the colors.
The first color in the color table is the background color and the remaining nonzero colors are the class colors. You can automatically determine the number of classes in several ways. Because having class counts can be useful, the following code computes them and as a result finds out how many classes there are (16 plus background).
library(raster)
mapd <- raster("...") # Use the path to your raster data source
classes <- table(getValues(mapd)) # Tabulation of class counts
colors <- mapd@legend@colortable # Class colors
plot(mapd, col=colors[1:length(classes)+1], colNA=colors[1], axes=FALSE, box=FALSE)
You have to provide a color palette:
library("raster")
mapd <- raster("MCD12C1_T1_2011-01-01_rgb_1440x720.TIFF")
plot(mapd, col=terrain.colors(255), axes=FALSE)
The rasterVis package has lattice based methods for plotting Raster
objects (spplot(...)
):
library("rasterVis")
spplot(mapd)