Exercise 13. Log-scale
Now we are going to change the axes to log scales to account for the fact that the population distribution is skewed. Let's start by defining an object p
that holds the plot we have made up to now:
p <- murders %>% ggplot(aes(population, total, label = abb, color = region)) +
geom_label()
To change the x-axis to a log scale we learned about the scale_x_log10()
function. We can change the axis by adding this layer to the object p
to change the scale and render the plot using the following code:
p + scale_x_log10()
This exercise is part of the course
Data Science Visualization - Module 2
Exercise instructions
Change both axes to be in the log scale on a single graph. Make sure you do not redefine p
- just add the appropriate layers.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
p <- murders %>% ggplot(aes(population, total, label = abb, color = region)) + geom_label()
## add layers to p here