i make several maps (one each species of dataset), somehow not able achieve looking for.
i want plot every species record in map, create maps single dot in each one... cannot understand wrong script. me? thank you!
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) (i in seq_along(data$species)) { pdf(file=paste0("map ", data$species[[i]],".pdf"), onefile=f) plot(disaggregate(crop(elevation,newextent), 1, method="bilinear"), col = land.pal, legend=f) points(data$lat[[i]],data$long[[i]], col="black") ##the error must here, cannot fix 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
currently, iterating through every single value of species column , not species whole group , pass 1 point of lat , long, 1 row being passed in for
loop.
hence, consider by
slice data frame species factor, iteratively passing every sliced data frame function. not shown below by
can return named list of objects equal groupings of factor(s) here being species:
by(data, data$species, fun = function(df) { pdf(file=paste0("map ", df$species[[1]],".pdf"), onefile=false) plot(disaggregate(crop(elevation,newextent), 1, method="bilinear"), col = land.pal, legend=false) points(df$lat, df$long, col="black") dev.off() })
Comments
Post a Comment