The earlier post Mapping Australia SA4 Polygoons using d3 and Mapbox was my first Australia SA4 map using d3 and mapbox and was mainly focused on the challenges and how I found my way around. The Viz uses a random number generator to create the color scale for the Map, and the main reason demonstrate how it will work if the map had data binded to it. Finally, the wait it over! Eureka!

The process to bind the data to the map was clear, however, I needed to find an efficient way to do it. I was working on another map for work where I opened two files - geojson and csv, looping through to match the SA4 code and then appending the data to the geojson file. The csv data was constant and would not change at anytime. It made me think that am doing too much work on the browser and I could append the data to the geojson before loading it to the browser. So, I decided to do it through R. All I had to do was to append the population data from 2011 census to the geojson file. In my mind, “Easy, read geojson, readcsv, append, write geojson!”. So I went through a few blogs and achieved it using the code:

library(geojsonio)
library(sp)
library(rgdal)
library(rgeos)
library(dplyr)
setwd("Github/Census 2011/geojson manipulation/")
map = readOGR("2011sa4.geojson", "OGRGeoJSON")
data <- read.csv("/home/shannon/Documents/ABS/2011/data/2011_BCP_SA4_for_AUST_short-header/2011 Census BCP Statistical Areas Level 4 for AUST/AUST/2011Census_B01_AUST_SA4_short.csv") %>%
  select(region_id,Tot_P_P,Tot_P_M,Tot_P_F)
joined <- merge(map, data, by.x="SA4_CODE", by.y="region_id")
geojson_write(joined, file = "sa4population.geojson")

Using the same code, I replaced the color scale and random number generator with the population size and added the size of both Male and Female population to the sidebar. This is the first iteration, and will be updated whenever, I think about anything interesting. The map is accessible through here