Mosaic plot
The spine plot you have created in the previous exercise allows you to study missing data patterns between two variables at a time. This idea is generalized to more variables in the form of a mosaic plot.
In this exercise, you will start by creating a dummy variable indicating whether the United States was involved in the production of each movie. To do this, you will use the grepl() function, which checks if the string passed as its first argument is present in the object passed as its second argument. Then, you will draw a mosaic plot to see if the subject's gender correlates with the amount of missing data on earnings for both US and non-US movies.
The biopics data as well as the VIM package are already loaded for you. Let's do some exploratory plotting!
Note that a proprietydisplay_image()function has been created to return the output from the latestVIMpackage version. Make sure to expand theHTML Viewer section.
Deze oefening maakt deel uit van de cursus
Handling Missing Data with Imputations in R
Oefeninstructies
- Feed the
biopicsdata into thedplyrpipeline. - Create a dummy variable
is_US_moviethat isTRUEifcountrycontains the string"US"and isFALSEotherwise. - Draw a mosaic plot that shows the amount of missing data in
"earnings"split by"is_US_movie"and"sub_sex", while remembering to pass variable names as strings.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Prepare data for plotting and draw a mosaic plot
___ %>%
# Create a dummy variable for US-produced movies
mutate(is_US_movie = grepl(___, ___)) %>%
# Draw mosaic plot
mosaicMiss(highlight = ___,
plotvars = c(___, ___))
# Return plot from latest VIM package - expand the HTML viewer section
display_image()