Let’s Try Some Visualisation

So I am going to try to use this blog to capture programming tricks and examples of R coding, data visualisation and general musing that I find interesting. This is mainly for personal use and as a nice memory tool.

Below is an example from Claus Wilke’s multiscales package. The details can be found here. I like that it uses geom_sf and one can also use the value suppressing uncertainty palettes. I often want to communicate uncertainty in cartographic mapping and this provides a much better way to do that. More on that article here.

So now for the example that one can use as…thanks Claus

library(ggplot2)
library(multiscales)
colors <- scales::colour_ramp(
  colors = c(red = "#AC202F", purple = "#740280", blue = "#2265A3")
)((0:7)/7)

p<-ggplot(US_polling) +
  geom_sf(aes(fill = zip(Clinton_lead, moe_normalized)), color = "gray30", size = 0.2) +
  coord_sf(datum = NA) +
  bivariate_scale("fill",
    pal_vsup(values = colors, max_desat = 0.8, pow_desat = 0.2, max_light = 0.7, pow_light = 1),
    name = c("Clinton lead", "uncertainty"),
    limits = list(c(-40, 40), c(0, 1)),
    breaks = list(c(-40, -20, 0, 20, 40), c(0, 0.25, 0.50, 0.75, 1.)),
    labels = list(waiver(), scales::percent),
    guide = "colourfan"
  ) +
  theme_void() +
  theme(
    legend.key.size = grid::unit(0.8, "cm"),
    legend.title.align = 0.5,
    plot.margin = margin(5.5, 20, 5.5, 5.5)
  )
p


Citation

BibTex citation:

@online{dewitt2018
author = {Michael E. DeWitt},
title = {Let’s Try Some Visualisation},
date = 2018-07-04,
url = {https://michaeldewittjr.com/articles/2018-07-04-let-s-try-some-visualisation},
langid = {en}
}

For attribution, please cite this work as:

Michael E. DeWitt. 2018. "Let’s Try Some Visualisation." July 4, 2018. https://michaeldewittjr.com/articles/2018-07-04-let-s-try-some-visualisation