Lab 1 - Intro to Shiny
General Lab Instructions. (15)
- Ensure your lab meets these basic lab requirements: https://github.ubc.ca/ubc-mds-2016/general/blob/master/general_lab_instructions.md
- Ensure that the low-level flow of your writing is appropriate, with full sentences and using proper English, spelling, and grammar.
- Ensure that the high-level structure of your solution is clear and thorough for each answer, with a well-thought-out organization of concepts that avoids repetition.
- This assignment is to be completed as a shiny app. However, your answers should be submitted as both a
.Rmdmarkdown file you create in RStudio (you can add your answers directly to this one) along with a rendered
- Ensure your submission is formatted clearly as to distinguish between questions and answers. For an example, check the
formatting_templatedirectory of the course repository.
- Ensure that your markdown submission as a whole is easy to read: use appropriate formatting that clearly distinguishes between our questions and your answer, between different sub-parts of your answer, and with visible differences between code and English.
- Deploy your Shiny app to shinyapps.io and upload your source code to your assignment repository. Sometimes deployment will introduce bugs, so make sure to save some time for debugging! The shinyapps.io console logs are very helpful here.
Exercise 1 - Interactive plots with Shiny and the US violent crimes 1975-2015 dataset
Create an interactive visualization using Shiny and the Marshall dataset of violent crimes in 68 US cities from 1975-2015.
Q1a: Choose and justify visual encoding and interaction idioms. (9)
- Consider what questions might be answerable with this dataset, and consider what visual encodings would be appropriate that take into account these inferred tasks and the characteristics of the dataset.
The Marshall project dataset has a few different dimensions to consider:
- Year (quantitative)
- Region (spatial, categorical)
- Crime Type (categorical)
- Crime Counts (quantitative)
Answerable Questions: We can search the data for trends, outliers, or features. We could inspect the distribution of crime counts, or investigate dependencies, correlations, or similarities between attributes.
It would make sense to show this data spatially (focused on region), linearly (focused on year).
- Also consider how to add interactivity that would further support these tasks through dynamic changes, either of aspects of the visual encoding or by providing alternate visual encodings.
Tweak aspects of the visual encoding:
- We could allow the user to change the point size, color, or transparency of marks to allow for the best visibility.
- We could allow the user to change graph scales to obtain more granular resolution of certain points.
Alternative visual encodings:
- We could allow the user to change between shape and color channel encoding for categorical variables such as crime type.
- We could allow the user to change the encoding of year from the position on a common scale to color luminance or color saturation.
- Explain and justify your choice of visual encodings with respect to the dataset characteristics and the tasks that you inferred, including an analysis of marks and channels.
- We will most likely use points as our data marks for crime counts.
- Year: As an ordered, quantitative variable, year would be best represented as the position on a common scale. Time is often represented on the x-axis of a graph, so perhaps if we make a graph we could put year on that scale.
- Region: As an unordered categorical attribute, there are too many regions to use color, shape, or motion to delineate between them. Therefore, it would be best to use spatial region to distinguish between regions--this could easily be accomplished with a geographic representation.
- Crime Type: As an unordered categorical attribute with ~5 types, crime type would be well delineated with color or shape.
- For each visual channel used, state "Channel X encodes attribute Y of type Z".
- Channel "position on a common scale" encodes attribute "Year" of type "ordered, quantitative"
- Channel "position on a common scale" encodes attribute "crime rate" of type "quantitative".
- For each mark used, state "Mark of type X encodes item Y".
- Mark of type "point" encodes crime rate.
Q1b: Create a base visualization within the Shiny framework by visually encoding the dataset, according to your choices above. (12)
Q1c: Make the visualization interactive. (64)
You should implement at least five input methods. You may tie these to any of the attributes in the dataset or to any aspects of the visual encoding.
- slider input - change mark size
- numeric input - change mark transparency
- color input - change mark color
- date range - filter by dates
- select input - change crime type
- radio buttons - change mark type
- text input - change graph title
- checkbox input - filter by region
Deploy your app to shinyapps.io and include the source code in your homework repository.
Briefly explain the functionality of your interactive Shiny app in your writeup.
This dataset was highly dimensional, so instead of creating a visually noisy space with multiple channels, I chose to instead allow for heavy filtering of the data. My visualization is specifically focused on visualizing trends of a specific crime type in a specific region over time. However, this is not without drawbacks, making comparisons between crime types and regions nearly impossible.
I have allowed for the user to change several aspects of the visualization, separable into two types:
Changing visual encoding:
- Change point size
- Change point transparency
- Change point color
- Filter by year
- Filter by crime type
- Filter by region
- Change plot title
Q2 (optional) Add more interactive functionality (6)
Dig further into the docs to go above and beyond the suggestions listed above and implement some novel functionality.