Start by loading the murders
dataset.
To create the scatterplot we add a layer with geom_point
. The
aesthetic mappings require us to define the x-axis and y-axis variables,
respectively. So the code looks like this:
p1 <- murders %>% ggplot(aes(x = , y = )) +
geom_point()
except we have to define the two variables x
and y
.
1. Make a plot with the population size on the x-axis and the
total number of gun murders on the y-axis. Store the resulting
ggplot object in p1
.
Note that if we don’t use argument names, we can obtain the same plot by making sure we enter the variable names in the right order like this:
murders %>% ggplot(aes(population, total)) +
geom_point()
2. Remake the plot but now with total in the x-axis and population in the
y-axis. Store this second plot in p2