问题
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