The purpose of this lab is to practise generating interactive data visualisations and to demonstrate the value of interaction.
For this lab, you will interact with plots to change the view of the data. For some questions, you will need to take snapshots of the interactive plot and embed the resulting PNG file in your R Markdown document to show that you have completed the question.
NOTE that you can take a snapshot of your ‘plotly’ plot by clicking the little camera icon at the top of the plot.
This lab is broken into two sections, requiring TWO submissions: a non-shiny part and a shiny part. You must submit .Rmd and .html for the non-shiny part and just a .Rmd for the shiny part.
The data set is a CSV file, nzpolice-proceedings.csv,
which was derived from “Dataset 5” of Proceedings
(offender demographics) on the policedata.nz
web site.
We can read the data into an R data frame with
read.csv().
crime <- read.csv("nzpolice-proceedings.csv")
crime$Month <- as.Date(crime$Date)
crime$Year <- as.POSIXlt(crime$Date)$year + 1900
typeCount <- table(crime$ANZSOC.Division)
crime$Type <- factor(crime$ANZSOC.Division,
levels=names(typeCount)[order(typeCount)])For this lab we will drop the year 2014 (for which we only have partial data).
Some questions will use the “raw” crime data above, with
one row per incident, and some questions will use the table-of-counts
version of the data below, with one row per combination of crime type
and month.
For each data visualisation in this Lab, we will be interested in answering the following question:
For specific data visualisations there may be additional specific questions of interest.
For this question, you must use the ‘plotly’ package.
Write R code to produce an interactive version of the plot below.
NOTE that the legend labels are the
Abbreviated labels.
NOTE that you need to add the full-length crime type labels to the tooltips in this plot.
NOTE that this figure is 8 inches wide and 6 inches high.
Use zoom and pan to inspect the trends in Homicide and Miscellaneous Acts. Embed a snapshot of a zoomed view, which should look something like the one below.
Use interactions with the legend to select ONLY Public Order Offences and Dangerous or Negligent Acts so that we can see them clearly without other overlapping lines. Embed a snapshot of your final view of the data, which should look something like the one below.
Use tooltips to identify the exact month when the sudden dip in Dangerous or Negligent Acts occurred.
Describe at least 4 examples of interesting differences in trends over time for different types of crime, based on the above interactions and your own further explorations.
For this question you must use the ‘plotscaper’ package.
For this question we will limit the exploration to just Jan 2021 onwards (to limit the data size).
Write R code to produce (linked) interactive bar plots of crime types, age groups, and dates, as shown below.