#Load libraries
library(raster)
library(rasterVis)

#read the file biomas_1985_rs.tif with Brazil land cover for 1985
#file contains 31 land cover type
bio1985=raster("biomas_1985_rs.tif")

#use the function reclassify to simplify the data
#from 31 to 3 cover types: natural, deforested, and water
m = c(-Inf,0,NA, 0.5,13,0, 14,21,1, 22,Inf,2)
rcm = matrix(m, ncol=3, byrow=T)
desf1985=reclassify(bio1985,rcm)

#use ratify to convert from continuous to discrete data
desf1985 = ratify(desf1985)
rat = levels(desf1985)[[1]]
rat$landcover = c("Natural","Altered","Water")
levels(desf1985) = rat

#set colors for the map
#check the link below for more colors
#http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf
cc=c("darkolivegreen4","bisque3","blue")

#generate land cover map
p1 = levelplot(desf1985,margin=F, colorkey=T,
               par.settings=custom.theme(region=cc),
               scales = list(cex=1, tck=-0.5),
               xlab="",ylab="",main="1985 Land Cover Map")
#plot map
print(p1)