R in 3 Months Week 3 (Data Visualization)

What is the most confusing thing about ggplot?

Please put your answer in the chat!

Agenda

  1. Housekeeping

  2. ggplot

  3. Data viz questions

  4. Data viz exercise

  5. Next week

Housekeeping

Housekeeping

  • Zoom links for live sessions and co-working sessions

  • Check in on co-working sessions

  • Feedback location

  • Ally

  • Live session during catch-up week (October 22) on using AI with R. Email us your questions!

Indentation

ggplot

Data Viz Questions

== and lowercase x and y

penguins |>
  filter(species == "Gentoo")
ggplot(
  data = penguins, # why can't I use == within this function?
  mapping = aes(
    x = flipper_length_mm, # must be lowercase x and y
    y = body_mass_g
  )
) +
  geom_point()

Color vs fill

Why is it that the color= option is treated differently by geom_point and geom_col? The logic seems inconsistent here since color= is used as if it is fill= by geom_point. What if I want the scatter plot to have black dots with outline color different by island?

Assessment break

You want a scatter plot of bill_length_mm vs. bill_depth_mm with black-filled dots whose outline color differs by island. Which geom_point() call does this?

  1. geom_point(aes(color = island), fill = "black")
  2. geom_point(aes(color = island), fill = "black", shape = 21)
  3. geom_point(aes(fill = island), color = "black")
  4. geom_point(aes(outline = island), color = "black")

Assessment break

You want a scatter plot of bill_length_mm vs. bill_depth_mm with black-filled dots whose outline color differs by island. Which geom_point() call does this?

  1. geom_point(aes(color = island), fill = "black")
  2. geom_point(aes(color = island), fill = "black", shape = 21)
  3. geom_point(aes(fill = island), color = "black")
  4. geom_point(aes(outline = island), color = "black")

Is there a “correct” order to put geoms, scales, themes, etc?

Ensuring legible labels when flipping a bar chart

I wanted to do this as a horizontal bar chart rather than a vertical column chart, but I couldn’t figure out how to adjust the placement of the labels so that they were legible.

Width of bars in bar charts

Reordering bar charts

Wrapping long text in charts

Removing the legend

Is there a way to remove the legend altogether?

Data Viz Exercise

Data Viz Exercise

Next Week

You’ll be learning about Quarto!

  • Course assignment: learn the basics of Quarto

  • Project assignment: take what you’ve done so far and turn it into a Quarto document