geom_dhb: Geom for DHB hexmap

View source: R/geom_dhb.R

geom_dhbR Documentation

Geom for DHB hexmap

Description

A ggplot2 geom for the District Health Board hexmap: geom_dhb wraps geom_map and geom_label_dhb wraps geom_text.

Usage

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)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). For geom_dhb and geom_region you must specify map_id with the unit names, and for geom_dhbtri and geom_regiontri additionally specify class_id giving the order of triangles within a hex. The radius aesthetic controls the size of the hexes

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 colour = "white" or cex = 3.

na.rm

If FALSE, warn when missing values are removed

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them.

coord

If TRUE, set the aspect ratio and plot limits. The main reason to have coord=FALSE is if you are stacking two geom_dhb layers

short

If TRUE, use the ‘short’ (mostly 1-character) abbreviations for DHB or region names

Value

The geoms

See Also

dhb_fixname

Examples

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)


tslumley/DHBins documentation built on July 31, 2022, 11:44 p.m.