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)
vectorplot(r2, par.settings=RdBuTheme())
vectorplot(r3, par.settings=PuOrTheme())
## If no cluster is provided, streamplot uses parallel::mclapply except
## with Windows. Therefore, next code could spend a long time under
## Windows.
streamplot(r1)
## With a cluster
hosts <- rep('localhost', 4)
cl <- makeCluster(hosts)
streamplot(r2, cl=cl,
par.settings=streamTheme(symbol=brewer.pal(n=5,
name='Reds')))
stopCluster(cl)
## Without parallel
streamplot(r3, parallel=FALSE,
par.settings=streamTheme(symbol=brewer.pal(n=5,
name='Greens')))
## Configuration of droplets and streamlets
streamplot(s, layout=c(1, 3), droplet=list(pc=.2), streamlet=list(L=20),
par.settings=streamTheme(cex=.6))
Run the code above in your browser using DataLab