0

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.

1 Answers1

0

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.

Oscar Perpiñán
  • 4,491
  • 17
  • 28
  • Dear Oscar, thank you. Your answer aided to figure out the solution, however, I was interested in reverse only the arrow directions and keep the r1 (raster) as the background. I'm looking for a way to make the arrows shows the direction from lower to high values instead of the standard high to low. – Bruno Garcia Luize Nov 30 '21 at 11:13
  • I have modified my answer. – Oscar Perpiñán Nov 30 '21 at 17:29