# NOT RUN {
library(sp)
library(maptools)
data(wrld_simpl)
library(spdplyr)
library(raster)
wrld_simpl %>% mutate(NAME = "allthesame", REGION = row_number())
wrld_simpl %>% transmute(alpha = paste0(FIPS, NAME))
wrld_simpl %>% filter(NAME %in% c("New Zealand", "Australia", "Fiji"))
# }
# NOT RUN {
wrld_simpl %>% arrange(LON)
wrld_simpl %>% slice(c(9, 100))
wrld_simpl %>% dplyr::select(UN, FIPS)
wrld_simpl %>% rename(`TM_WORLD_BORDERS_SIMPL0.2NAME` = NAME)
wrld_simpl %>% distinct(REGION, .keep_all = TRUE) %>%
arrange(REGION) ## first alphabetically in REGION
wrld_simpl %>% arrange(REGION, desc(NAME)) %>% distinct(REGION, .keep_all = TRUE) ## last
# }
# NOT RUN {
## we don't need to use piping
slice(filter(mutate(wrld_simpl, likepiping = FALSE), abs(LON - 5) < 35 & LAT > 50), 4)
## works with Lines
#as(wrld_simpl, "SpatialLinesDataFrame") %>%
# mutate(perim = rgeos::gLength(wrld_simpl, byid = TRUE))
# }
# NOT RUN {
## summarise/ze can be used after group_by, or without
wrld_simpl %>% filter(REGION == 150) %>% summarize(max(AREA))
wrld_simpl %>% group_by(REGION) %>% summarize(max(AREA)) %>%
plot(col = rainbow(nlevels(factor(wrld_simpl$REGION)), alpha = 0.3))
# }
# NOT RUN {
## group_by and summarize
# }
# NOT RUN {
g <- wrld_simpl %>% group_by(REGION) %>%
summarize(alon = mean(LON), mxlat = max(LAT), mxarea = max(AREA))
g %>% mutate(ar = factor(REGION)) %>% spplot("ar")
w <- wrld_simpl
w$ar <- factor(w$REGION)
spplot(w, "ar")
# }
# NOT RUN {
# compare what rgeos gives
##spplot(rgeos::gUnionCascaded(w, id = w$ar)) ## good grief, is this compelling . . .
## this is hardly a clean dissolve
##plot(rgeos::gUnionCascaded(w, id = w$ar), col = rainbow(nlevels(factor(w$ar)), alpha = 0.5))
# }
Run the code above in your browser using DataLab