r - Save map so it can be automatically use in by-loops -
i make several species maps. problem when using by
command, has create map every time iteration made. know if possible save map somehow can used automatically.
i tried recordplot()
function, gives me error , generate blank maps:
library(raster) elevation <- getdata("alt", country = "es", mask=f) slope <- terrain(elevation, opt = "slope",neighbors=4) aspect <- terrain(elevation, opt = "aspect",neighbors=4) hill <- hillshade(slope, aspect, 40, 270) newextent<-extent(-7.99, -2.87, 39.9, 41.5) land.pal <- colorramppalette(c("#336600", "#f3ca89", "#d9a627", "#a49019", "#9f7b0d", "#996600", "#b27676", "#c2b0b0", "#e5e5e5", "#ffffff"), space="lab") (1000) plot(disaggregate(crop(elevation,newextent), 20, method="bilinear"), col = land.pal, legend=f) map <- recordplot() by(data, data$species, fun = function(data) { pdf(file=paste0("map ", data$species,".pdf"), onefile=f, width=6,height=3, pointsize=1) plot.new() map points(data$lat, data$long, pch=21, bg="black", cex=0.85) dev.off() })
thank in advance
data:
lat long species -6.99 40.49 sp1 -5.05 40.60 sp1 -3.30 40.02 sp1 -7.51 40.86 sp1 -3.18 40.24 sp1 -3.83 40.08 sp1 -7.28 40.91 sp1 -7.74 40.53 sp1 -7.72 40.69 sp1 -4.36 40.06 sp1 -5.90 40.51 sp2 -5.56 40.07 sp2 -3.52 40.19 sp3 -6.29 40.93 sp3 -6.77 40.12 sp3 -7.11 40.77 sp4 -5.81 40.88 sp4 -5.27 40.68 sp4 -6.31 40.34 sp4 -6.13 40.32 sp4 -6.73 40.99 sp4 -5.32 40.71 sp4 -6.17 40.97 sp4 -4.77 40.92 sp4 -6.45 40.58 sp5 -5.54 40.39 sp5 -6.56 40.66 sp5 -5.27 40.37 sp5
Comments
Post a Comment