[R-sig-Geo] color schemes for landcover plots of multiple rasters

Oscar Perpiñán Lamigueiro oscar.perpinan at gmail.com
Tue Sep 25 13:21:20 CEST 2012


MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Although it is not fully automatic, you may be interested in this
example (http://procomun.wordpress.com/2012/02/20/maps_with_r_2/):
 library(raster)
 library(rasterVis)
 library(colorspace)
 ## http://neo.sci.gsfc.nasa.gov/Search.html?group=3D20
 landClass <- raster('241243rgb-167772161.0.TIFF')
 ## China and India
 ext <- extent(65, 135, 5, 55)
 landClass <- crop(landClass, ext)
 ## Codes: http://eoimages.gsfc.nasa.gov/images/news/NasaNews/ReleaseImages=
/LCC/Images/lcc_key.jpg
 landClass[landClass %in% c(0, 254)] <- NA
 landClass <- cut(landClass, c(0, 5, 11, 14, 16))
 classes <- c('FOR', 'LAND', 'URB', 'SNOW')
 nClasses <- length(classes)
 rng <- c(minValue(landClass), maxValue(landClass))
 ## define the breaks of the color key
 my.at <- seq(rng[1]-1, rng[2])
 ## the labels will be placed vertically centered
 my.labs.at <- seq(rng[1], rng[2])-0.5
 levelplot(landClass, at=3Dmy.at, margin=3DFALSE,
          col.regions=3Dterrain_hcl(nClasses),
          colorkey=3Dlist(labels=3Dlist(labels=3Dclasses, ## classes names =
as labels
                          at=3Dmy.labs.at)))
 I will try to modify rasterVis::levelplot to work automatically with
 categorical data.
 Best,
 Oscar.
steven mosher <moshersteven at gmail.com> writes:
 > I'm plotting a series ( a few hundred )  of  rasters that are filled with
 > landcover data,   integers
 >
 > Normally, these are  integers such as  c(11,12,21,22,23,31,32,41,42,43,5=
1,
 >  etc etc)
 > where each value corresponds to a landcover type.
 >
 > I want all of these plots to have consistent colors and legends. However,
 > not every plot has
 > a complete set of land cover types.   What I tried was the following.
 >
 > I took all the landcover values in the raster and reclassified them so t=
hat
 > I got a  seq from
 > 1..n.   and then I made a vector of colors the same length
 >
 > However, when a land type if missing I still get   errors.  I tried using
 >  breaks() and that
 > helped a little but I would still get  errors
 >
 > Here is a toy example
 >
 > r <- raster(nrow=3D10,ncol=3D10)
 > #  slot in some values
 > r[1:12]<-0
 > r[13:34]<-1
 > r[35:76]<-2
 > r[77:95]<-3
 > r[96:100]<-4
 >
 > #  define colors
 > myColors <- c("black","green","orange","pink","blue")
 >
 > plot(r,col=3DmyColors)
 >
 > #  swicth the 4 to 0
 > r <- subs(r,data.frame(Id=3D c(0,1,2,3,4), v=3Dc(0,1,2,3,0)))
 >
 > plot(r,col=3DmyColors)
 >
 > Another way to ask this is how do I get the function to recognize that I
 > watch categorical colors instead of
 > continuous ones. or should I change the colors dynamically according to =
the
 > actual values found in that
 > particular map.
 >
 > I tried  breaks() no joy
 >
 >
 > Steve
 >
 > 	[[alternative HTML version deleted]]
 --=20
 Oscar Perpi=C3=B1=C3=A1n Lamigueiro
 Dpto. Ingenier=C3=ADa El=C3=A9ctrica
 EUITI-UPM
Date: Tue, 25 Sep 2012 13:20:45 +0200
In-Reply-To: <CAFFLneRsK9rG8L4pgAHqqkhbcHNSOcixoKroFzhT_tN8vKDN1A at mail.gmai=
l.com>
	(steven mosher's message of "Sun, 23 Sep 2012 22:27:38 -0700")
Message-ID: <87ipb21h82.fsf at gmail.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux)



More information about the R-sig-Geo mailing list