ggplot practice II

Lecture 6

Dr. Elijah Meyer

NC State University
ST 295 - Spring 2025

2025-01-23

Checklist

– Have you cloned the today’s AE repo?

– Have you cloned your homework repo?

  > Due Monday (11:59pm) on Gradescope 
  > Please reach out if you have any questions

– Are you keeping up with prepare material?

  > This includes making sure you can render a document to a PDF!
  

– Quiz-1 is graded. Reach out if you have questions!

– Quiz-2 comes out at noon; due Monday (11:59pm)

Video recordings

This class does not have classroom capture

We will Zoom record the screen, and I will post the videos to Moodle.

Note: I reserve the right to stop posting the videos if no one starts to show up…

Warm-up

We have calculated different summary statistics in this class so far. What does it mean to be a robust statistic?

Warm-up

Robust statistics

Warm-up

Why is body_mass_g not in quotes, but “Body Mass (grams)” is?

penguins |>
  ggplot(
    aes(x = body_mass_g, y = flipper_length_mm, shape = species)
  ) +
  geom_point() + 
  labs(x = "Body Mass (grams)",
       y = "Flipper length (mm)")

Warm-up

Let’s introduce the kbl() function in R to control significant digits

You can do A LOT more with tables. Check the link out here

Today’s activity

– learn the difference between color and fill

– learn how to break apart a plot by another variable

– use color to our advantage

– layer geoms together

Goal

In-summary

– Color outlines geom shapes; fill fills the color in (with a scatterplot being the exception)

– We can use facet_wrap() and facet_grid() to break plots apart by variables

– We need to think about using color strategically, instead of just coloring points blue for fun. Specifically, we can think about things like color blind friendly pallets.

– We can layer on multiple geoms… and order DOES matter!