Title: | Hexmaps for NZ District Health Boards |
---|---|
Description: | Draws stylized choropleth maps -- hexagonal maps and triangular multiclass hex maps -- for New Zealand District Health Boards and Regional Council areas. These allow faceted, coloured displays of quantitative information for comparison across District Health Boards or Regional Councils. The preprint Lumley (2019) <arXiv:1912.04435> is based on the methods in this package. |
Authors: | Thomas Lumley |
Maintainer: | Thomas Lumley <[email protected]> |
License: | GPL-3 |
Version: | 1.3 |
Built: | 2024-11-04 04:03:32 UTC |
Source: | https://github.com/tslumley/dhbins |
The distribution of cars per household across New Zealand District Health Boards, based on data from the 2013 Census
data("dhb_cars")
data("dhb_cars")
A data frame with 20 observations on the following 5 variables.
dhb
District Health Board name
none
Number of households with no cars
one
Number of households with one car
two
Number of households with two cars
more
Number of households with three or more cars
Statistics New Zealand http://archive.stats.govt.nz/Census/2013-census/data-tables/dhb-tables.aspx
data(dhb_cars) tris<-tri_alloc(dhb_cars[,-1], c("green","gold","orange","goldenrod"), names=dhb_cars$dhb ) dhtri(tri_colours=tris, legend=list(fill=c("green","gold","orange","goldenrod"), border=NA, legend=c("0","1","2","3+"), title="Cars/Household") )
data(dhb_cars) tris<-tri_alloc(dhb_cars[,-1], c("green","gold","orange","goldenrod"), names=dhb_cars$dhb ) dhtri(tri_colours=tris, legend=list(fill=c("green","gold","orange","goldenrod"), border=NA, legend=c("0","1","2","3+"), title="Cars/Household") )
Converts popular variants of the DHB or region names into the versions used as keys in this package.
dhb_fixname(names) region_fixname(names)
dhb_fixname(names) region_fixname(names)
names |
vector of strings with DHB or region names |
vector of strings with standardised DHB or region names
dhb_fixname( c("Hawkes Bay","Capital & Coast","Counties")) region_fixname(c("Nelson City","Wellington region","Auckland","Tasman district","Nelson Tasman"))
dhb_fixname( c("Hawkes Bay","Capital & Coast","Counties")) region_fixname(c("Nelson City","Wellington region","Auckland","Tasman district","Nelson Tasman"))
The 20 District Health Boards are the main administrative and funding units of the NZ national health system. The Regions are the second-level government divisions . These functions draw stylised maps of the DHBs and regions, along the lines of "statebins" for the US states. The hexagon for each location can be coloured and sized to show numeric data, and it can also be split into six triangles to show proportion or composition data.
dhbin(radius = NULL, hex_colours = "lightskyblue", DHB_names=NULL, text_colour = "black", legend_opts = NULL, border = NULL, short = FALSE,cex=0.8) dhtri(radius = NULL, tri_colours, DHB_names=NULL, text_colour = "black", legend_opts = NULL, short=FALSE,cex=0.8) regionbin(radius = NULL, hex_colours = "lightskyblue", region_names=NULL, text_colour = "black", legend_opts = NULL, border = NULL, short = FALSE, tasman=TRUE, cex=0.7) regiontri(radius = NULL, tri_colours, region_names=NULL, text_colour = "black", legend_opts = NULL,short=FALSE, tasman=TRUE, cex=0.7)
dhbin(radius = NULL, hex_colours = "lightskyblue", DHB_names=NULL, text_colour = "black", legend_opts = NULL, border = NULL, short = FALSE,cex=0.8) dhtri(radius = NULL, tri_colours, DHB_names=NULL, text_colour = "black", legend_opts = NULL, short=FALSE,cex=0.8) regionbin(radius = NULL, hex_colours = "lightskyblue", region_names=NULL, text_colour = "black", legend_opts = NULL, border = NULL, short = FALSE, tasman=TRUE, cex=0.7) regiontri(radius = NULL, tri_colours, region_names=NULL, text_colour = "black", legend_opts = NULL,short=FALSE, tasman=TRUE, cex=0.7)
radius |
Vector of radius measurements for the coloured part of each hexagon, with 1 as a full hexagon. If any are greater than 1, the vector is scaled to have maximum value 0.95, which is also the default value for all hexagons. If it has names, they are matched to the DHB names or common alternative names. |
hex_colours |
Vector of colours as names or hashtag colours. If it has names, they are matched to the DHB names or common alternative names. |
tri_colours |
6-column matrix of colours for the six triangles in each hexagon. If it has row names, they are matched to the DHB names or common alternative names. |
DHB_names , region_names
|
Vector of DHB names or region names. If |
text_colour |
Colour for the label on all the hexagons. |
legend_opts |
a list with arguments to |
border |
|
short |
If |
tasman |
The Tasman District and Nelson City are considered as separate regions in most contexts, but as forming the Nelson Region in some contexts. Use |
cex |
character expansion factor |
Called for its side-effect
Lumley T (2019) Stylised Choropleth Maps for New Zealand Regions and District Health Boards. arXiv:1912.04435
tri_alloc
for the Sainte-Laguë method to allocate triangles based on counts
data(dhb_cars) tris<-tri_alloc(dhb_cars[,-1], c("green","gold","orange","goldenrod"), names=dhb_cars$dhb ) dhtri(tri_colours=tris, legend=list(fill=c("green","gold","orange","goldenrod"), border=NA, legend=c("0","1","2","3+"), title="Cars/Household") ) households<-rowSums(dhb_cars[,-1]) names(households)<-dhb_cars$dhb dhbin(radius=sqrt(households)) title(main="Number of households in private dwellings") opar<-par(mfrow=c(2,3),mar=c(1,1,1,1)) z<-rnorm(20) for(i in 1:6){ z<-(rnorm(20)+z)/sqrt(2) z1<- (z+4)/8 col_z<-rgb(colorRamp(c("blue", "white","red"))(z1),max=255) dhbin(hex_colours=col_z,border="grey",short=TRUE, legend_opts=list(fill=c("red","white","blue"), legend=c("High","Medium","Low"), title=paste("Thing",i)) ) } par(opar) data(region_ethnicity) cols<-tri_alloc(as.matrix(region_ethnicity[,-1]), colours=hcl.colors(5,"Set2"),names=region_ethnicity$Area) regiontri(tri_colours=cols,text_colour="white", legend_opts=list(fill=hcl.colors(5,"Set2"), title="Ethnicity", legend=names(region_ethnicity)[2:6])) title(main="New Zealand regions")
data(dhb_cars) tris<-tri_alloc(dhb_cars[,-1], c("green","gold","orange","goldenrod"), names=dhb_cars$dhb ) dhtri(tri_colours=tris, legend=list(fill=c("green","gold","orange","goldenrod"), border=NA, legend=c("0","1","2","3+"), title="Cars/Household") ) households<-rowSums(dhb_cars[,-1]) names(households)<-dhb_cars$dhb dhbin(radius=sqrt(households)) title(main="Number of households in private dwellings") opar<-par(mfrow=c(2,3),mar=c(1,1,1,1)) z<-rnorm(20) for(i in 1:6){ z<-(rnorm(20)+z)/sqrt(2) z1<- (z+4)/8 col_z<-rgb(colorRamp(c("blue", "white","red"))(z1),max=255) dhbin(hex_colours=col_z,border="grey",short=TRUE, legend_opts=list(fill=c("red","white","blue"), legend=c("High","Medium","Low"), title=paste("Thing",i)) ) } par(opar) data(region_ethnicity) cols<-tri_alloc(as.matrix(region_ethnicity[,-1]), colours=hcl.colors(5,"Set2"),names=region_ethnicity$Area) regiontri(tri_colours=cols,text_colour="white", legend_opts=list(fill=hcl.colors(5,"Set2"), title="Ethnicity", legend=names(region_ethnicity)[2:6])) title(main="New Zealand regions")
A ggplot2
geom for the District Health Board hexmap: geom_dhb
wraps geom_map
and geom_label_dhb
wraps geom_text
.
geom_dhb(mapping = NULL, data = NULL, stat="identity",..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,coord=TRUE) geom_label_dhb(mapping = NULL, data = NULL, ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, short=FALSE) geom_dhbtri(mapping = NULL, data = NULL, stat="identity",..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,coord=TRUE) geom_region(mapping = NULL, data = NULL, stat="identity",..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,coord=TRUE) geom_label_region(mapping = NULL, data = NULL, ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,short=FALSE) geom_regiontri(mapping = NULL, data = NULL,stat="identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,coord=TRUE)
geom_dhb(mapping = NULL, data = NULL, stat="identity",..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,coord=TRUE) geom_label_dhb(mapping = NULL, data = NULL, ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, short=FALSE) geom_dhbtri(mapping = NULL, data = NULL, stat="identity",..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,coord=TRUE) geom_region(mapping = NULL, data = NULL, stat="identity",..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,coord=TRUE) geom_label_region(mapping = NULL, data = NULL, ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,short=FALSE) geom_regiontri(mapping = NULL, data = NULL,stat="identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,coord=TRUE)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. Usually inherited from the plot data |
stat |
The statistical transformation to use on the data for this layer, as a string. |
... |
Other arguments passed on to layer(), such as aesthetics, used to set an aesthetic to a fixed value, like |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends? |
inherit.aes |
If |
coord |
If |
short |
If |
The geoms
data(immune) summary(immune) immune$vax_pct<-cut(immune$Pcttotal,c(0,.80,.85,.90,.95,1)) ggplot(immune)+ geom_dhb(aes(fill=vax_pct,map_id=dhb_fixname(DHB)))+ scale_fill_viridis_d(drop=FALSE)+ geom_label_dhb(short=TRUE,colour="white") ## size variation, plus stacking to show the full-size hexes underneath, ## plus no labels ggplot(immune)+ geom_dhb(aes(map_id=dhb_fixname(DHB)),fill="white",colour="grey",coord=FALSE)+ geom_dhb(aes(fill=vax_pct,map_id=dhb_fixname(DHB),radius=sqrt(Ntotal)),alpha=0.5)+ scale_fill_viridis_d(drop=FALSE) data(immune_long) ggplot(immune_long) + geom_dhb(aes(map_id=dhb_fixname(DHB),fill=pct_vax), alpha=0.5,colour="lightgrey") + scale_fill_viridis_d(drop=FALSE)+ geom_label_dhb(short=TRUE,colour="black",cex=3)+ facet_wrap(~ethnicity) data(dhb_cars) tris<-tri_alloc(dhb_cars[,-1], c("0","1","2","3+"), names=dhb_cars$dhb ) tri_data<-data.frame(DHB=rep(rownames(tris),6), cars=as.vector(tris), tri_id=rep(1:6,each=nrow(tris))) ggplot(tri_data)+ geom_dhbtri(aes(map_id=DHB,class_id=tri_id, fill=cars),alpha=0.5)+ scale_fill_viridis_d()+ geom_label_dhb(short=TRUE) data(region_ethnicity) tri_eth<-tri_alloc(as.matrix(region_ethnicity[,-1]), classes=c("Asian","Euro","Maori","MELAA","Pacific"), names=region_ethnicity$Area) tri_data<-data.frame(Region=rep(rownames(tri_eth),6), ethnicity=as.vector(tri_eth), tri_id=rep(1:6,each=nrow(tri_eth))) ggplot(tri_data)+ geom_regiontri(aes(map_id=Region,class_id=tri_id, fill=ethnicity))+ geom_label_region(colour="Black", short=TRUE,cex=3)
data(immune) summary(immune) immune$vax_pct<-cut(immune$Pcttotal,c(0,.80,.85,.90,.95,1)) ggplot(immune)+ geom_dhb(aes(fill=vax_pct,map_id=dhb_fixname(DHB)))+ scale_fill_viridis_d(drop=FALSE)+ geom_label_dhb(short=TRUE,colour="white") ## size variation, plus stacking to show the full-size hexes underneath, ## plus no labels ggplot(immune)+ geom_dhb(aes(map_id=dhb_fixname(DHB)),fill="white",colour="grey",coord=FALSE)+ geom_dhb(aes(fill=vax_pct,map_id=dhb_fixname(DHB),radius=sqrt(Ntotal)),alpha=0.5)+ scale_fill_viridis_d(drop=FALSE) data(immune_long) ggplot(immune_long) + geom_dhb(aes(map_id=dhb_fixname(DHB),fill=pct_vax), alpha=0.5,colour="lightgrey") + scale_fill_viridis_d(drop=FALSE)+ geom_label_dhb(short=TRUE,colour="black",cex=3)+ facet_wrap(~ethnicity) data(dhb_cars) tris<-tri_alloc(dhb_cars[,-1], c("0","1","2","3+"), names=dhb_cars$dhb ) tri_data<-data.frame(DHB=rep(rownames(tris),6), cars=as.vector(tris), tri_id=rep(1:6,each=nrow(tris))) ggplot(tri_data)+ geom_dhbtri(aes(map_id=DHB,class_id=tri_id, fill=cars),alpha=0.5)+ scale_fill_viridis_d()+ geom_label_dhb(short=TRUE) data(region_ethnicity) tri_eth<-tri_alloc(as.matrix(region_ethnicity[,-1]), classes=c("Asian","Euro","Maori","MELAA","Pacific"), names=region_ethnicity$Area) tri_data<-data.frame(Region=rep(rownames(tri_eth),6), ethnicity=as.vector(tri_eth), tri_id=rep(1:6,each=nrow(tri_eth))) ggplot(tri_data)+ geom_regiontri(aes(map_id=Region,class_id=tri_id, fill=ethnicity))+ geom_label_region(colour="Black", short=TRUE,cex=3)
The report measures the number of children who turned the milestone age of 5 years between 01-Jul-2019 and 30-Sep-2019 and who have completed their age appropriate immunisations by the time they turned the milestone age. The target is 95%. Children are only counted once, according to 'prioritised ethnicity': the priority order is Māori, Pacific, Asian, other, NZ European. The immune_long
variant is in long form with separate rows for each ethnicity, and with missing values where the population size is too small.
data("immune")
data("immune")
For immune
, a data frame with 20 observations on the following 19 variables.
DHB
name of District Health Board
Ntotal
Number of children
Vaxtotal
Number who completed their vaccinations
Pcttotal
Proportion
NNZE
,VaxNSE
,PctNZE
the same, for children of NZ European ethnicity
NMaori
,VaxMaori
,PctMaori
the same, for children of Māori ethnicity
NPacific
,VaxPacific
,PctPacific
the same, for children of Pacific ethnicities
NAsian
,VaxAsian
,PctAsian
the same, for children of Asian ethnicities
NOther
,VaxOther
,PctOther
the same, for children of other ethnicities
For immune_long
, a data frame with 120 observations on the following 3 variables.
DHB
name of District Health Board
ethnicity
ethnicity: a factor with levels total
NZE
Maori
Pacific
Asian
Other
pct_vax
percent vaccinated, a factor with levels [0,0.8)
[0.8,0.85)
[0.85,0.9)
[0.9,0.95)
[0.95,1)
New Zealand Health Indicators, 2019
Statistics New Zealand. Health Indicators. http://archive.stats.govt.nz/browse_for_stats/snapshots-of-nz/nz-social-indicators/Home/Health/childhood-immunisation.aspx
data(immune) summary(immune) immune$vax_pct<-cut(immune$Pcttotal,c(0,.80,.85,.90,.95,1)) ggplot(immune)+ geom_dhb(aes(fill=vax_pct,map_id=dhb_fixname(DHB)))+ scale_fill_viridis_d(drop=FALSE)+ geom_label_dhb(short=TRUE,colour="white") data(immune_long) ggplot(immune_long) + geom_dhb(aes(map_id=dhb_fixname(DHB),fill=pct_vax),alpha=0.5,colour="lightgrey") + scale_fill_viridis_d(drop=FALSE)+ geom_label_dhb(short=TRUE,colour="black")+ facet_wrap(~ethnicity) cols<-c("goldenrod","red","orange","gold","springgreen") with(immune, dhbin(hex_colours=cols[vax_pct], legend_opts=list(fill=cols, legend=c("<80","80-85","85-90","90-95","95+"), title="Immunisation coverage (pct)") )) ## Add some transparency with(immune, dhbin(hex_colours=adjustcolor(cols[vax_pct],alpha.f=.5), legend_opts=list(fill=cols, legend=c("<80","80-85","85-90","90-95","95+"), title="Immunisation coverage (pct)") ))
data(immune) summary(immune) immune$vax_pct<-cut(immune$Pcttotal,c(0,.80,.85,.90,.95,1)) ggplot(immune)+ geom_dhb(aes(fill=vax_pct,map_id=dhb_fixname(DHB)))+ scale_fill_viridis_d(drop=FALSE)+ geom_label_dhb(short=TRUE,colour="white") data(immune_long) ggplot(immune_long) + geom_dhb(aes(map_id=dhb_fixname(DHB),fill=pct_vax),alpha=0.5,colour="lightgrey") + scale_fill_viridis_d(drop=FALSE)+ geom_label_dhb(short=TRUE,colour="black")+ facet_wrap(~ethnicity) cols<-c("goldenrod","red","orange","gold","springgreen") with(immune, dhbin(hex_colours=cols[vax_pct], legend_opts=list(fill=cols, legend=c("<80","80-85","85-90","90-95","95+"), title="Immunisation coverage (pct)") )) ## Add some transparency with(immune, dhbin(hex_colours=adjustcolor(cols[vax_pct],alpha.f=.5), legend_opts=list(fill=cols, legend=c("<80","80-85","85-90","90-95","95+"), title="Immunisation coverage (pct)") ))
Number of people, by ethnicity, for the New Zealand regions, based on the 2013 Estimated Resident Population.
data("region_ethnicity")
data("region_ethnicity")
A data frame with 16 observations on the following 6 variables.
Area
a factor with level Auckland region
Bay of Plenty region
Canterbury region
Gisborne region
Hawke\'s Bay region
Manawatu-Wanganui region
Marlborough region
Nelson region
Northland region
Otago region
Southland region
Taranaki region
Tasman region
Waikato region
Wellington region
West Coast region
Asian
number of people
Euro_Other
number of people
Maori
number of people
MELAA
number of people
Pacific
number of people
https://figure.nz/table/foip3RBvo69sO3J3, originally from Statistics New Zealand
data(region_ethnicity) summary(region_ethnicity)
data(region_ethnicity) summary(region_ethnicity)
This implements the Webster/Sainte-Laguë method to allocate six triangles in each hexagon, in proportion to counts in two or more classes.
tri_alloc(countmatrix, colours, classes=colours, names = rownames(countmatrix))
tri_alloc(countmatrix, colours, classes=colours, names = rownames(countmatrix))
countmatrix |
A matrix of counts with a column for each class and a row for each hexagon. |
colours , classes
|
A vector of class names, or colour names with one for each class |
names |
A vector of names, for each row of |
Matrix of class names, with six columns. The rownames will be set to names
if provided.
data(dhb_cars) tri_alloc(dhb_cars[,-1], c("green","gold","orange","goldenrod"), names=dhb_cars$dhb ) tri_alloc(dhb_cars[,-1], c("0","1","2","3+"), names=dhb_cars$dhb )
data(dhb_cars) tri_alloc(dhb_cars[,-1], c("green","gold","orange","goldenrod"), names=dhb_cars$dhb ) tri_alloc(dhb_cars[,-1], c("0","1","2","3+"), names=dhb_cars$dhb )