Code and Visualisation
library(rgeos)
## rgeos version: 0.3-26, (SVN revision 560)
## GEOS runtime version: 3.4.2-CAPI-1.8.2 r3921
## Linking to sp version: 1.2-5
## Polygon checking: TRUE
library(maptools)
## Loading required package: sp
## Checking rgeos availability: TRUE
library(leaflet)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:rgeos':
##
## intersect, setdiff, union
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(htmlwidgets)
library(htmltools)
vic.lga.shp <- readShapeSpatial("~/Desktop/vmlite_lga_cm/vmlite_lga_cm.shp")
## Warning: use rgdal::readOGR or sf::st_read
## Warning: use rgdal::readOGR or sf::st_read
lga<-read.csv("~/Desktop/lga.csv")
merge.lga<-sp::merge(vic.lga.shp, lga, by="lga_name", duplicateGeoms = TRUE)
bins <- quantile(lga$median_house_price,probs = seq(0,1,.2), names = FALSE, na.rm = TRUE)
pal <- colorBin("Reds", domain = lga$median_house_price, bins = bins,pretty = FALSE )
p <- leaflet(merge.lga) %>%
setView(lng = 147, lat = -36.5, zoom = 6)
labels <- sprintf(
"<strong>%s</strong><br/>%g AUD",
merge.lga$lga_name,
merge.lga$median_house_price
) %>% lapply(htmltools::HTML)
title <- tags$div(HTML('<h3>Victorian LGA Median House Price of Year 2011</h3>'))
p %>% addPolygons(fillColor = ~pal(median_house_price),weight = 2,opacity = 1,color = "white", dashArray = "3", fillOpacity = 0.7, highlight = highlightOptions(weight = 3,color = "black", dashArray = "", fillOpacity = 0.7, bringToFront = TRUE), label=labels,labelOptions = labelOptions(style = list("font-weight" = "normal",padding = "3px 8px"),textsize = "15px",direction = "auto"))%>%
addLegend(pal = pal, values = ~median_house_price, opacity = 1, title = "Median House Price",position = "bottomright") %>%
addControl(title, position = "topright")