Interactive Visualisations

In the previous visualisations the user can’t change the core information which is shown, in effect the visualisations are ‘static’.

The most useful visualisations don’t limit the user to a static analysis, they incorporate interactivity, where the visualisation can be changed by the user varying relevant parameters.

The user is not dictated to, instead they are guided and can choose their own analysis journey. Incorporating intuitive elements can allow even more insights.

There is always one key issue which needs to be addressed with data analysis and interactive visualisations - how to share them with those who will use them?

Essentially the humble web browser is the one application we know will most likely be on any device capable of using the visualisations.

RShiny is a very powerful interactive visualisation tool for R used in a web browser, however it requires a separate RShiny data server to be running, which not everyone may have the access needed to implement.

Assuming we have a method of sharing a webpage (eg GitPages, static website instance), let’s explore some visualisations which function completely within a web browser without the need for a separate data server.

Crosstalk Filters

Crosstalk is an extension package designed to work with htmlwidgets package, both of which allow interactive visualisations in a Notebook environment in a web browser.

Crosstalk is not infinitely configurable, but will provide slider, checkbox and dropdown filters which will work with several of the htmlwidgets visualisation tools, including Plotly/ggplotly, DataTables and Leaflet.

Demonstration 2 - Plotly/ggplotly Visualisation with Crosstalk filters

Plotly for R is an advanced and diverse open source visualisation library, which also includes a function ggplotly() which wraps around a ggplot generated plot and immediately adds useful interactivity and features.

To enable the Crosstalk filters to work with the visualisation, we created a shared data resource, which is the used by the visualisation tools.

Let’s create a visualisation which explores correlations between the two data sources earlier. We will plot SEIFA percentile/rank versus Private Health participation for each Postcode for a user chosen range of Taxable Income.

This is achieved by

  • Creating a shared resource tax_seifa_shared, which is a narrow/long format of the combined tax and seifa data created previously.
  • use bscols() to format a visualisation with two rows, one for the filter_slider() and one for the plot.

Can you draw any interesting conclusions from the visualisations?

tax_seifa_bc = tax2022_raw %>% 
  filter( State !="Unknown" & State!="Overseas" ) %>% 
  mutate(TaxableIncome_dollarspr = round(TaxableIncome_dollars/Returns/1000,0)) %>% 
  mutate(PrivateHealth_percentpp = round(PrivateHealth_returns/Returns*100,0)) %>% 
  inner_join( x= ., y = seifa2021_raw, by = "Postcode") %>%
  select(State, Returns, Postcode, ieo_percentile, TaxableIncome_dollarspr, PrivateHealth_percentpp )

tax_seifa_bc_shared <- SharedData$new(tax_seifa_bc)

plot_bc <-  tax_seifa_bc_shared %>%
            ggplot(aes(x=ieo_percentile, y=PrivateHealth_percentpp, )) +
            geom_point(aes(fill=State, size=Returns, text=paste0("Postcode: ", Postcode)), alpha=0.5, stroke=0.1) + 
            scale_fill_brewer(palette="Paired") +
            scale_size(range = c(1, 8), name="Returns")
bscols(
  widths=c(12,12),
  filter_slider("TaxableIncome_dollarspr", "Mean Taxable Income per return ($K)", tax_seifa_bc_shared, column=~TaxableIncome_dollarspr, step=1, width = "100%"),
  ggplotly(plot_bc))