Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clarify the sp() from table process #41

Open
mdsumner opened this issue May 11, 2017 · 0 comments
Open

clarify the sp() from table process #41

mdsumner opened this issue May 11, 2017 · 0 comments

Comments

@mdsumner
Copy link
Owner

Example

library(choroplethrMaps)

data(state.map)
##?state.map
head(state.map)

## use spbabel to restore to sp
library(spbabel)

## we need to use particular naming conventions 

library(dplyr)
babel_table <- state.map %>% 
  mutate(island_ = !hole)  %>% 
  rename(object_ = id, x_ = long, y_ = lat, order_ = order, branch_ = group ) %>% 
  dplyr::select(-piece, -hole)

# library(ggplot2)
# ggplot(state.map, aes(long, lat, group=group, fill = group)) + 
#   geom_polygon() + guides(fill = FALSE)
# 
# ggplot(babel_table, aes(x_, y_, group=branch_, fill = branch_)) + 
#   geom_polygon() + guides(fill = FALSE)


## convert to sp
sp.state.map <- spbabel::sp(babel_table)
#sp.state.map <- spbabel::sp(babel_table, crs = "+init=epsg:4326")


## convert to sf
library(sf)
sf.state.map <- sf::st_as_sf(sp.state.map)
sf.state.map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant