Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interpolate region on vectorplot?

Continue from my previous question 'create vectorplot from velocity dataset'. I still have 2 question how to make the figure look like below:

1) How to make the region interpolation? I have tried used interpolate = TRUE but didn't work.
2) How to define the arrow symbol with the same length (It's mean the arrow only show the velocity direction)

Here my data uv.nc and syntax I have written:

library (raster)
flname <- 'uv.nc'
u <- raster(flname, varname = 'U')
v <- raster(flname, varname = 'V')
uv <- stack(u,v)
s <- sqrt(u^2 + v^2)

library(rasterVis)
jet <- colorRampPalette(c('#00007F', 'blue', '#007FFF', 'cyan','#7FFF7F', 'yellow', '#FF7F00', 'red', '#7F0000'))
range = seq(0, 0.5, 0.05)
vectorplot(uv, isField = 'dXY', interpolate = TRUE, col.regions = jet, region=s, length=0.05)

enter image description here

like image 325
Eko Susilo Avatar asked Aug 11 '26 02:08

Eko Susilo


1 Answers

(First question) The interpolate argument needs the panel.levelplot.raster function to be called by levelplot (used internally by vectorplot to render the background). However, this does not work directly with the current version of rasterVis. You can try this trick:

levelplot(s, 
          panel = panel.levelplot.raster, 
          interpolate = TRUE,
          margin = FALSE) + 
vectorplot(uv, isField = 'dXY', region = FALSE)

(Second question) The length of the arrows is determined by your data, because you are using dXY = TRUE. Thus, you should use modify your data to get vectors with the same magnitude.

uv0 <- uv / s
vectorplot(uv0, isField = 'dXY', region = s)
like image 78
Oscar Perpiñán Avatar answered Aug 13 '26 21:08

Oscar Perpiñán



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!