Skip to content

Instantly share code, notes, and snippets.

@fauxvalue
Last active June 30, 2019 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fauxvalue/d362e0183614f649cf5acf0642445f2a to your computer and use it in GitHub Desktop.
Save fauxvalue/d362e0183614f649cf5acf0642445f2a to your computer and use it in GitHub Desktop.
Plot NSW AEC data on leaflet map
# how to draw a map -- and some geospatial points -- using R
require(data.table)
require(leaflet)
# get the data
pollingPlaces <- as.data.table(read.csv("https://tallyroom.aec.gov.au/Downloads/GeneralPollingPlacesDownload-24310.csv", skip = 1))
nswReps <- as.data.table(read.csv("https://tallyroom.aec.gov.au/Downloads/HouseStateFirstPrefsByPollingPlaceDownload-24310-NSW.csv", skip = 1))
# inner join to add lat and longtitude data
nswReps[pollingPlaces[, list(PollingPlaceID, Latitude, Longitude)],
`:=` (lat = i.Latitude, long = i.Longitude),
on = 'PollingPlaceID']
# part 1: out first map
# create a simple map -- show all pollling places in NSW
nswVotingPlaces <- leaflet(nswReps) %>%
addTiles() %>%
addCircleMarkers(lat = ~lat, lng = ~long, popup = ~DivisionNm,
col = 'red', stroke = FALSE, fillOpacity = 0.01)
print(nswVotingPlaces)
@fauxvalue
Copy link
Author

fixed a little big

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment