I have 65 MOD11A2 images. I set the date using the as.Date function and then I created a time series stack using the timeStackMODIS function of the bfastSpatial package. I wanted to create a time series plot of pixels following this post. The problem is that I was unable to set the date in the x axis. Any thoughts? Here is an example of my code.

library(bfastSpatial)
library(raster)
library(rgdal)

setwd("my_dir")

#create list
list = list.files(path = "my_dir", full.names = FALSE, pattern = "\\.tif$" )

#time series layer stack of the list using the bfastspatial
m8 = timeStackMODIS(list, pattern = glob2rx("\\.tif$"))

plot_ts <- function(x) {
  plot(x[[1]])
  z <- c(click(x, n=1, show=FALSE))
  plot(z, type='l', lwd=2, ylab='y', xlab='time', las=1)
  z
}

z <- plot_ts(m8)

The resulting graph is this one

To set the date I used this code:

li<-as.data.frame(list.files(pattern = ".tif|.TIF"))
li$nn<-paste0(substr(li[,1],1,9),format(as.Date(substr(li[,1],10,16), "%Y%j"),"%Y.%m.%d"),substr(li[,1],17,75))
for(i in 1:nrow(li)){
  file.rename(as.character(li[i,1]),li[i,2])
}

0 Answers