Get startedGet started for free

Exercise 1: Customizing plots - watch and learn

To make the plot on the right in the exercise from the last set of assessments, we had to reorder the levels of the states' variables.

This exercise is part of the course

Data Science Visualization - Module 2

View Course

Exercise instructions

  • Redefine the state object so that the levels are re-ordered by rate.
  • Print the new object state and its levels (using levels) so you can see that the vector is now re-ordered by the levels.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

library(dplyr)
library(ggplot2)
library(dslabs)
dat <- us_contagious_diseases %>%
filter(year == 1967 & disease=="Measles" & !is.na(population)) %>% mutate(rate = count / population * 10000 * 52 / weeks_reporting)
state <- dat$state 
rate <- dat$count/(dat$population/10000)*(52/dat$weeks_reporting)
Edit and Run Code