0

I have a tibble df that looks like this:

        id       sex     rating
1       43      male         10
2       44    female          8
3       45      male          7
4       46      male          3
5       47    female          5

How would I go about using ggplot2 to represent this data on a scatterplot with one dot for each id, female ratings on the y-axis, and male ratings on the x-axis? Do I have to modify df before using geom_point()? Or without modifying df, how could I set aes(x = ..., y = ...) within geom_point()?

KLG
  • 173
  • 1
  • 12

1 Answers1

0

Figured it out.

df %>%
  pivot_wider(names_from = sex, values_from = rating) %>%
  ggplot(aes(x = male, y = female)) +
  geom_point()
KLG
  • 173
  • 1
  • 12