I'm trying to plot a vectorplot with arrows for vector fields going from lower to high values. This is the reverse direction for vectorplot function. The function has an option for this, however specifiyng reverse = T doesn't change the results. How can I solve this? A reproducible example from ?vectorplot
library(raster); library(rasterVis)
proj <- CRS('+proj=longlat +datum=WGS84')
df <- expand.grid(x=seq(-2, 2, .01), y=seq(-2, 2, .01))
df$z <- with(df, (3*x^2 + y)*exp(-x^2-y^2))
r1 <- rasterFromXYZ(df, crs=proj)
df$z <- with(df, x*exp(-x^2-y^2))
r2 <- rasterFromXYZ(df, crs=proj)
df$z <- with(df, y*exp(-x^2-y^2))
r3 <- rasterFromXYZ(df, crs=proj)
s <- stack(r1, r2, r3)
names(s) <- c('R1', 'R2', 'R3')
vectorplot(r1, reverse=FALSE)# reverse Logical, TRUE if arrows or streamlets go against the direction of the gradient.
vectorplot(r1, reverse=TRUE) # produce same results as vectorplot(r1, reverse=FALSE)
Thank you all for the little help.
The reverse
option is only available when the object is a vector field (isField = TRUE
). Try this:
sa <- terrain(r1, opt=c("slope", "aspect"))
vectorplot(sa, isField = TRUE)
vectorplot(sa, isField = TRUE, reverse = TRUE)
You can display the original raster as the background with the region
argument:
vectorplot(sa, isField = TRUE, reverse = TRUE, region = r1)
I have improved the text in the help page.