Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Visualization Best Practices in R

Cursus bekijken

Oefeninstructies

  • Change the geometry from geom_col() to geom_point() .
  • Increase point size with size = 2.
  • Switch to a log scale with scale_y_log10().
  • Lighten the background with theme_minimal().

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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()
Code bewerken en uitvoeren