We made a plot of total murders versus population and noted a strong relationship. Not surprisingly, states with larger populations had more murders.
library(dslabs)
data(murders)
population_in_millions <- murders$population/10^6
total_gun_murders <- murders$total
plot(population_in_millions, total_gun_murders)
Keep in mind that many states have populations below 5 million and are
bunched up. We may gain further insights from making this plot in the
log scale. Transform the population_in_millions
and total_gun_murders
variables using the log10
transformation, storing them as population_in_millions_log
and total_gun_murders_log
and then plot them using the same method shown above.