MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Visualization Best Practices in R

Lihat Kursus

Petunjuk latihan

  • 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().

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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()
Edit dan Jalankan Kode