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
.
This exercise is part of the course
Visualization Best Practices in R
Exercise instructions
Modify
filter()
to pull the years1992
and2002
.Modify Aesthetics to:
- Plot the cases for 1992 by country.
reorder()
y-axis by the number of cases.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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()