Chapter 6 – Plotting Maps

In this chapter, we are going to do something different from the previous chapters: maps. Mapping is a convenient way to plot data where the geographical aspect is important.

For those of you in Sociology 1205, this chapter covers the EDA module for unit 6. You will find the scripts in your R Studio cloud workspace.

In this chapter, we are still going to use ggplot2 as our main package to construct our plots, but because maps are so different in terms of how they visualize data, we are going to also introduce additional libraries and functions. The specific benefit of maps is to possibly extract patterns that are tied to geographic units, countries, states, or, counties.

In the first tutorial, we will learn how to make basic maps. Then, in the subsequent tutorials, we’ll use different datasets and packages to plot specific information. The last tutorial advises caution on the use of maps as opposed to other forms of visualization.

Learning Objectives

In this chapter, we will cover the following topics:

  • how to create maps in ggplot2;
  • how to plot data on maps;
  • the strengths and weaknesses of maps compared to other forms of visualization.

Tutorial 1 – Part 1

Tutorial 1 – Part 2

Tutorial 2 – Part 1

Tutorial 2 – Part 2

Tutorial 3 – Part 1

Tutorial 3 – Part 2

Tutorial 4

Key functions used in this chapter

  • map_data(): the function that loads data to map;
  • geom_polygon(): the function that creates plots based on joining points;
  • coord_map(): the function that sets a map projection;
  • colorRampPalette(): the function that creates a custom brewer palette;
  • theme_map(): a plot theme specific for maps;
  • scale_fill_distiller(): the function that sets a color palette for maps;
  • geom_statebins(): the function that facets data by state in a uniform visualization.

Before moving on to the next chapter, or the exercise for those of you in Sociology 1205, test your understanding with the quiz below.

License

Icon for the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License

Visualizing Data with R Copyright © 2022 by Christine Monnier is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License, except where otherwise noted.

Share This Book