+ - 0:00:00
Notes for current slide
Notes for next slide

R for Data Science With Sports Applications

2023-11-08

1

Grammar of graphics: layers of a plot

  • Data

  • Geoms

  • Aesthetic mappings

  • Facets

2

Data

  • The underlying data frame.

  • Think rows and columns.

3

Geoms

  • Shapes to represent the data.

  • Individual geoms use one shape per row.

  • Group geoms use multiple rows to create a shape.

4

Aesthetic mappings

  • Map between the aesthetic properties of a geom and column of the data.
5

Facets

  • Also called small multiples.

  • Slice the rows into multiple sub populations.

6

Identify the components of the grammar of graphics

7

8

Identify the components (2)

9

10

Scatter plot: Data

  • Call the ggplot function and pass in a data frame.
ggplot(df)

11

Scatter plot: Aesthetic mappings

  • Pass the aes function with the mapping as a second argument.
ggplot(df, aes(x=AST, y=TOV))

12

Scatter plot: Geoms

  • Add a layer to use one point to represent one row.
ggplot(df, aes(x=AST, y=TOV)) + geom_point()

13

More mappings:

  • Shape and color
ggplot(df, aes(x=AST, y=TOV, color=Playoff, shape=Playoff)) +
geom_point()

14

Lab 2

  • Create a plot to understand the relationship between two pointers made and three pointers made.
  • Think about the data and the aesthetic mappings that you want.
  • Put it in an Rmarkdown file.
15

Grammar of graphics: layers of a plot

  • Data

  • Geoms

  • Aesthetic mappings

  • Facets

2
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow