Activity - ggplot 2

Meet ggplot

We’ll use the mammls dataset.

Here’s a quick rundown of how things work in ggplot. We’ll learn more as we go.

Make a chunk just to look at the data.

mammals

Make another one to dotplot the data. You need: - a pipe |> - ggplot() with some aesthetics - a +, - geom_point()

mammals |>
  ggplot(aes(x=total_sleep, y =brain_wt)) +
  geom_point()

Lets add a color aesthetic.

mammals |>
  ggplot(aes(x=total_sleep, y =brain_wt, color = exposure)) +
  geom_point()

Let’s add a facet()

mammals |>
  ggplot(aes(x=total_sleep, y =brain_wt, color = exposure)) +
  geom_point() +
  facet_wrap(~danger)

How do you know which aesthetics can be added?

?geom_point()

How do you choose a facet?

Choose something witih finite options.

Also see the ggplot cheatsheet under Resources