Created
June 30, 2019 13:47
-
-
Save fauxvalue/35ec1fa0cd468b45d8eee9501c091a6a to your computer and use it in GitHub Desktop.
Aus Fed election two party preferred and mines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# packages | |
require(data.table) | |
require(leaflet) | |
require(readxl) | |
twoppReps <- as.data.table(read.csv("https://tallyroom.aec.gov.au/Downloads/HouseTppByPollingPlaceDownload-24310.csv", skip = 1L)) | |
pollingPlaces <- as.data.table(read.csv("https://tallyroom.aec.gov.au/Downloads/GeneralPollingPlacesDownload-24310.csv", skip = 1)) | |
operatingMines <- as.data.table(read_excel("C:/Users/mcoog/Dropbox/blogs/operating_mines.xls")) | |
# inner join to add lat and longtitude data | |
twoppReps[pollingPlaces[, list(PollingPlaceID, Latitude, Longitude)], | |
`:=` (lat = i.Latitude, long = i.Longitude), | |
on = 'PollingPlaceID'] | |
# part 1 bin the data so that 0 = neutral, -100 = red and +100 = blue | |
swing_bins <- c(-100, -25, -10, -5, -2, -1, 0, 1, 2, 5, 10, 25, 100) | |
swing_pal <- colorBin(c("#f00505", "#fafafa", "#0520f0"), | |
bins = swing_bins) | |
ausMines_booths <- leaflet() %>% | |
addTiles() %>% | |
addCircleMarkers(data = twoppReps, | |
lat = ~lat, lng = ~long, popup = ~PollingPlace, | |
col = ~swing_pal(Swing), | |
stroke = FALSE, fillOpacity = 0.3, opacity = 0.3) %>% | |
addCircleMarkers(data = operatingMines, | |
lat = ~Latitude, lng = ~Longitude, popup = ~Name, | |
color = 'black', radius = 7, stroke = FALSE, | |
opacity = 0.50, fillOpacity = 0.50) | |
print(ausMines_booths) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment