1

Similar to mapping Australian cities, is there some native way to generate a state/territory choropleth in R?

I can see several methods documented but none which are complete (e.g. this looks somewhat promising, but lacks the original data)

library(rgdal)
library(spdplyr)
library(geojsonio)
library(rmapshaper)
# Load Australian State and Territories shapefile data
aus_ste <- readOGR(dsn = "/Users/kannishida/Downloads/STE11aAust", layer = "STE11aAust")
# Convert to GeoJSON
aus_ste_json <- geojson_json(aus_ste)
# Simplify the polygons to reduce the size
aus_ste_sim <- ms_simplify(aus_ste_json)
# Write GeoJSON file out to a file system
geojson_write(aus_ste_sim, file = "/Users/kannishida/Downloads/aus_ste.geojson")

An ideal solution would use data that exists on CRAN or reliable APIs - i.e. preference for reproducibility and reliability (by analogy, the same way we can get the world cities from CRAN via maps library)

library(maps)
library(dplyr)
world.cities %>% 
  filter(country.etc == "Australia")

The desired result is something along the lines of

enter image description here

stevec
  • 41,291
  • 27
  • 223
  • 311
  • you've tagged this with `mapdeck`, but I don't see any mapdeck issue / code ? – SymbolixAU Apr 16 '20 at 01:03
  • @SymbolixAU I read that it could do interactive map (i.e. building maps with javascript from an R interface), but as it turned out that was probably too broad (I don't think it can do choropleths specifically?). I will remove the tag (sorry if it wasted any time) – stevec Apr 16 '20 at 01:07
  • 1
    yes it _can_ do choropleths, for example, [these super-awesome extruded polygons](https://symbolixau.github.io/mapdeck/articles/layers.html#polygons). (Lots of code and examples on that page). – SymbolixAU Apr 16 '20 at 05:19
  • @SymbolixAU very nice! I had a look and they look great. Thanks, I will check out the code shortly – stevec Apr 16 '20 at 05:21

2 Answers2

3

The ozmaps package (on CRAN) contains this data as well as data for other ABS administrative regions.

library(ozmaps)
library(ggplot2)

ggplot(ozmap_states) +
  geom_sf(aes(fill = NAME)) +
  scale_fill_manual(values = viridis::cividis(9))

enter image description here

Ritchie Sacramento
  • 29,890
  • 4
  • 48
  • 56
1

The rnaturalearth and rnaturalearthhires packages can get the data for you:

library(mapview)
library(rnaturalearth)
library(rnaturalearthhires)
#library(sf)
#May need to:
# devtools::install_github('ropensci/rnaturalearthhires') 

aussie_states <- rnaturalearth::ne_states(country = 'australia')

head(aussie_states)
#> class       : SpatialPolygonsDataFrame 
#> features    : 6 
#> extent      : 112.9194, 153.6306, -38.07057, -9.240167  (xmin, xmax, ymin, ymax)
#> crs         : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
#> variables   : 83
#> names       :         featurecla, scalerank, adm1_code, diss_me, iso_3166_2, wikipedia, iso_a2, adm0_sr,                 name, name_alt, name_local,      type,   type_en, code_local, code_hasc, ... 
#> min values  : Admin-1 scale rank,         2,  AUS-1932,    1932,     AU-NSW,        NA,     AU,       1, Jervis Bay Territory,       NA,         NA,     State,     State,         NA,     AU.JB, ... 
#> max values  : Admin-1 scale rank,         2,  AUS-2657,    2657,    AU-X02~,        NA,     AU,       6,    Western Australia,       NA,         NA, Territory, Territory,         NA,     AU.WA, ...

map <- mapview::mapview(aussie_states )

map

Created on 2020-04-15 by the reprex package (v0.3.0)

mrhellmann
  • 5,069
  • 11
  • 38