Learning Quote of the Day

"It is not that I'm so smart. But I stay with the questions much longer."

― Albert Einstein

Opening connections

On a half-sheet of paper,

  • Write your name on the front and answer
    • What are the differences between a histogram and a boxplot?
    • What is the difference between a histogram and a barplot?
  • On the back of this sheet, answer the following questions:

    1. What is the definition of "observational unit"?
    2. What are the three properties of a tidy data set?
    3. What are the Five Named Graphs we explored in this chapter?

5NG and Grammar of Graphics Review

Run the following first in your console to create the data example:

# Load packages
library(dplyr)
library(ggplot2)

# Create data frame
simple_ex <- data_frame(
    A = c(1, 2, 3, 4),
    B = c(1, 2, 3, 4),
    C = c(3, 2, 1, 2),
    D = c("a", "a", "b", "b")
  )

View it

Let's view the data frame, which is in tidy format:

View(simple_ex)
A B C D
1 1 3 a
2 2 2 a
3 3 1 b
4 4 2 b

The Grammar of Graphics

  • A statistical graphic is a mapping of data variables to aes()thetic attributes of geom_etric objects.
  • A scatterplot has points as the geom_etric object
  • A linegraph has lines as the geom_etric object

1. Basic Scatterplot

  • the geom_etric objects are points
  • the aesthetic attributes are:
    • x-axis is variable A
    • y-axis is variable B
ggplot(data = simple_ex, mapping = aes(x = A, y = B)) + 
  geom_point()

1. Basic Scatterplot

ggplot(data = simple_ex, mapping = aes(x = A, y = B)) + 
  geom_point()

2. Scatterplot with Color

  • the geom_etric objects are points
  • the aesthetic attributes are:
    • x-axis is variable A
    • y-axis is variable B
    • color is variable D
ggplot(data = simple_ex, mapping = aes(x = A, y = B, color = D)) + 
  geom_point()

2. Scatterplot with Color

ggplot(data = simple_ex, mapping = aes(x = A, y = B, color = D)) + 
  geom_point()

3. Scatterplot with Sizes

  • the geom_etric objects are points
  • the aesthetic attributes are:
    • x-axis is variable A
    • y-axis is variable B
    • size is variable C
ggplot(data = simple_ex, mapping = aes(x = A, y = B, size = C)) + 
  geom_point()

3. Scatterplot with Sizes

ggplot(data = simple_ex, mapping = aes(x = A, y = B, size = C)) + 
  geom_point()

4. Line Graph

  • the geom_etric objects are lines
  • the aesthetic attributes are:
    • x-axis is variable A
    • y-axis is variable B
ggplot(data = simple_ex, mapping = aes(x = A, y = B)) + 
  geom_line()

4. Line Graph

ggplot(data = simple_ex, mapping = aes(x = A, y = B)) + 
  geom_line()

5. Line Graph with Color

  • the geom_etric objects are lines
  • the aesthetic attributes are:
    • x-axis is variable A
    • y-axis is variable B
    • color is variable D
ggplot(data = simple_ex, mapping = aes(x = A, y = B, color = D)) + 
  geom_line()

5. Line Graph with Color

ggplot(data = simple_ex, mapping = aes(x = A, y = B, color = D)) + 
  geom_line()

Finish Lab 3

To do for next time

  • Complete PS8 by 10 AM on Monday, October 3
  • Try the practice problems for the quiz here
  • No lab due on Tuesday next week

Plan for next time

  • Quiz #2 individually
  • Quiz #2 in groups of 3 (of your choosing)
  • Go over Quiz #2