Data

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")
  )

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

Recall

  • 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, aes(x=A, y=B)) + 
  geom_point()