Plot pixels time series

你说的曾经没有我的故事 提交于 2019-12-13 07:22:35

问题


I'm trying to create an interactive plot of a raster brick, whereby clicking on a pixel gives you a time series of data at that pixel. (My raster brick is about 345 image.)

This is what I did:

library(raster)

EVI <- "D:\\Modis_EVI\\Original\\EVI_Stack_single5000.tif"
y.EVI <- brick(EVI)
plot(as.numeric(click(y.EVI)), type="l", lwd=2)

But it does not plot at all. And when i try with a smaller stack like 4 images only it gives this error:

 Error in plot.window(…) : need finite 'xlim' values

Any advice please?


回答1:


Assuming you only want to allow the user to click once, you should specify n=1 in click. For example:

library(raster)
b <- brick(replicate(10, raster(matrix(runif(100), ncol=10))))

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(b)

Here's an example plot after clicking a cell...



来源:https://stackoverflow.com/questions/39053924/plot-pixels-time-series

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!