Week 1 practice
Some of the materials for Week 1 Workshop can be run live here. This provide an interactive playground to try out your code.
You will still be expected to download the workshop files each week, and run them in the workshops. The aim of this interactive environment is get you started with coding in R, and improve your familiarity. You are not expected to memorise any of the code syntax, the aim is to improve your confidence.
The tidyverse package has been loaded in this environment. It consists of many different packages. We will only be using ggplot2 here:
- ggplot2 - charts and plots
- dplyr - chaining data manipulation (filtering, mutation, reshaping)
- tibble - for effective data tables
- tidyr - helpful functions for cleaning data
- readr - functions for reading and writing data
- purrr - functional programming tools
- stringr - for manipulating text and character strings
- forcats - for dealing with categorical or ordinal data (factors)
Summarise the data. The data mtcars is available in the base version of R. we can use the function summary to do this.
Including Plots
You can also embed plots, for example:
Your first plot
Lets look at a different dataset - the mpg dataset is included in R:
Create a simple plot:
EXERCISE: Look at some summary statistics. What function will you use on the mpg data to do this?
Plot using colour by cty:
EXERCISE: Color the points by the class variable.
Copy and paste the previous code which colours by ‘cty’. What change do you need to make?