This presentation was made in RStudio using RMarkdown!

  • Can set output: ioslides_presentation in the header

Course Business


  • Anybody not on Slack/DataCamp yet?
  • Anybody not filled out the background survey?
  • Anybody not signed up to meet with me?
  • Anybody not have a working RStudio server account?

Lab 1 Recap

Structure of R commands

  • R commands are like sentences:

    • Functions are like verbs
    • Some arguments are like nouns (with particular roles)
    • (Other arguments are like prepositional phrases)


draw(picture, recipient = "me", material = "paint")
Component Role
draw function
picture argument value
recipient argument name
"me" argument value
material argument name
"paint" argument value

The "Pipe" operator (%>%)

  • takes the thing on the left, and (by default) puts it (or its output, if it is a function call) into the first argument slot for the function on the right

  • We'll do a lot more with this later

## Two equivalent expressions
arbuthnot %>% mutate(total = boys + girls)
mutate(arbuthnot, total = boys + girls)

The mutate() function

  • Takes a data frame as the main (first) argument
  • Takes a "formula" defining a new variable as the second argument
  • Output is a new data frame with a new column added
  • If we want to keep the new data frame, need to assign it to a named "container"
## Creates the column, but it immediately disappears
mutate(arbuthnot, total = boys + girls)
## Creates the column, and creates a brand new data frame
## that has both new and old variables (now we have two
## data frames, one with and one without the new variable)
new.arbuthnot <- mutate(arbuthnot, total = boys + girls)
## Creates the column, and overwrites the original data
## with a data frame that has new and old columns
arbuthnot <- mutate(arbuthnot, total = boys + girls)

Elements of data graphics

Elements of data graphics

  • Visual cues
    • position, size, color, etc.
  • Coordinate system
    • how are data points organized?
  • Scale
    • relationship between variable and distance in space
  • Context
    • what in the world is the data about?
  • Faceting
    • What are the sub-parts (facets) of the graph?

Source: Nathan Yau, Data Points