Skip to content

Instantly share code, notes, and snippets.

@Robinlovelace
Last active February 10, 2019 16:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robinlovelace/13364cb7b1fbb8461517d7bab8b91243 to your computer and use it in GitHub Desktop.
Save Robinlovelace/13364cb7b1fbb8461517d7bab8b91243 to your computer and use it in GitHub Desktop.
url_csv = "https://github.com/d3/d3-plugins/raw/master/graph/data/cities.csv"
# read-in non-spatial table:
c = readr::read_csv(url_csv)
# convert to spatial:
cs1 = sf::st_as_sf(c, coords = c("longitude", "latitude"))
download.file(url = url_csv, destfile = "cities.csv")
# one liner with sf
cs2 = sf::read_sf("cities.csv", options=c("X_POSSIBLE_NAMES=longitude", "Y_POSSIBLE_NAMES=latitude"))
# static plot:
plot(cs2)
# interactive plot
library(tmap)
ttm()
qtm(cs2)
c_headerless = readr::read_csv(url_csv, skip = 1, col_names = F)
cs3 = sf::st_as_sf(c_headerless, coords = c(3, 2))
qtm(cs3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment