Start by loading the dplyr and ggplot2 library as well as the
murders
data.
library(dplyr)
library(ggplot2)
library(dslabs)
data(murders)
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() +
geom_point(aes(x=, y=))
except we have to define the two variables x
and y
.
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
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.
Remake the plot but now with total in the x-axis and population in the
y-axis. Store this second plot in p2