I have the next code:
list_data <- list.files(pattern="*NDVI",full.names=T)
stack my data using:
data <- stack(list_data)
and the names of layers is:
> names(data)
[1] "Max_NDVI_2000" "Max_NDVI_2001" "Max_NDVI_2002"
[4] "Max_NDVI_2003" "Max_NDVI_2004" "Max_NDVI_2005"
[7] "Max_NDVI_2006" "Max_NDVI_2007" "Max_NDVI_2008"
[10] "Max_NDVI_2009" "Max_NDVI_2010" "Max_NDVI_2011"
then, i need change names of layer: 2000, 2001, ......, 2011,, I'm using
names(data) <- 2000:2011
but I get X2000, X2001 ...
> names(data)
[1] "X2000" "X2001" "X2002"
[4] "X2003" "X2004" "X2005"
[7] "X2006" "X2007" "X2008"
[10] "X2009" "X2010" "X2011"
however, if I use a characters the output is correct:
> names(data) <- month.abb
> names(data)
[1] "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug"
[9] "Sep" "Oct" "Nov" "Dec"
How the class of month.abb is character then, then I change
names(data) <- as.character(2000:2011)
but the output does not change.
**then, how I can change the names of layer? **.
PD: I need change the name for plot my data using the rasterVis package (levelplot function)
For changing the name of layers in plot you can use names.attr
:
levelplot(data,par.settings=BuRdTheme(),names.attr=c(as.character(2000:2011)))