The function 'vectorplot' displays the gradient within a matrix, but it is not clear how you get the values of the gradient at individual pixels. As an example:
library(raster)
library(rasterVis)
ex <- matrix( c(1,2,3,4,2,3,4,5,3,4,5,6,4,5,6,7), nrow=4)
r=raster(t(ex[,ncol(ex):1]), xmn=0.5,xmx=nrow(ex)+.5, ymn=0.5,ymx=ncol(ex)+0.5)
projection(r)=CRS("+init=epsg:27700")
persp(r,theta=-50,phi=20, shade=0.23,col="red")
vectorplot(r, scaleSlope=.1)
How do you get the values of the gradient? The function 'vectorplot' returns an object, but none of the fields appears to contain information related to the gradient that is displayed. The documentation says that the display is a side-effect, so if the gradient information is not returned, is there some other package that computes the gradient and returns that information to the user?
Thanks!