Converting to point chart
Our plot in the last exercise looked good, but what if we care about the values of the lower-end of the cases? It's hard for us to get a sense of their values because Brazil and Argentina are forcing the axis' upper range so high.
This is a good situation to switch to a log scale. However, remember that when on a log scale our stacking concept fails, so we should switch to a point chart! Note the additional filter added to the pipeline. What happens if you run the code without it?
This time, instead of modifying the data before sending to ggplot()
, we will add scale_y_log10()
to our plot and ggplot will take care of it for us.
To polish, use theme_minimal()
to lighten the chart up and increase the size
of the points from the default to 2
.
This exercise is part of the course
Visualization Best Practices in R
Exercise instructions
- Change the geometry from
geom_col()
togeom_point()
. - Increase point size with
size = 2
. - Switch to a log scale with
scale_y_log10()
. - Lighten the background with
theme_minimal()
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
amr_pertussis %>% filter(cases > 0) %>%
ggplot(aes(x = reorder(country, cases), y = cases)) +
# switch geometry to points and set point size = 2
geom_col() +
# change y-axis to log10.
___ +
# add theme_minimal()
___ +
coord_flip()