Session Ready
Exercise

Using emojis as plotting symbols

For the last exercise in this chapter, your task is to recreate a grouped dot plot you have seen before, but replace the plotting characters by emoji images. To do so, you will use the panel.xyimage() function in the latticeExtra package, which is similar to the panel.xyplot() function, except that plotting symbols are replaced by images whose locations (file names or URLs of JPEG or PNG image files) are specified as the pch argument.

Instructions
100 XP

The code to create a dataset containing only per-state median death rates for males and females, as we did in Chapter 2 earlier, is already provided. Using the dplyr package, the levels of State are reordered.

  • Load the latticeExtra package.

  • The URLs for the man and woman emojis are saved in variables emoji.man and emoji.woman.

  • Create a dot plot of state on the y-axis and median death rate on the x-axis.

  • Group the display by gender.

  • Use panel.xyimage as the panel function.

  • The pch argument should be a character vector containing emoji image URLs, one for each level of the grouping variable.

  • Set the cex argument (multiplier for symbol size) to 0.75 to make the symbols smaller than the default.