LoslegenKostenlos loslegen

Ordered point chart

Let's start by improving the point plot we saw in the slides.

First, change the data manipulation pipeline to filter to the years 1992 and 2002 instead of the default 2006-2016. Note that the array interestingCountries has been loaded and is the same as in the slides.

Now modify the plotting code to plot the new data, but this time, let's reorder the y-axis in descending order of cases for 1992.

Diese Übung ist Teil des Kurses

Visualization Best Practices in R

Kurs anzeigen

Anleitung zur Übung

  • Modify filter() to pull the years 1992 and 2002.

  • Modify Aesthetics to:

    • Plot the cases for 1992 by country.
    • reorder() y-axis by the number of cases.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

who_subset <- who_disease %>% 
	filter(
		countryCode %in% interestingCountries,
		disease == 'measles',
		year %in% c(2006, 2016) # Modify years to 1992 and 2002
	) %>% 
	mutate(year = paste0('cases_', year)) %>%
	arrange(year, region) %>%
	pivot_wider(names_from = year, values_from = cases)
 
# Reorder y axis and change the cases year to 1992
ggplot(who_subset, aes(x = log10(cases_2006), y = country)) +
	geom_point()
Code bearbeiten und ausführen