Getting maps from the maps package

The maps package has several pre-built maps that we can download and adapt. This recipe demonstrates the capabilities of these maps.

Getting ready

Install the maps package.

How to do it...

To get maps from the maps package, follow these steps:

  1. Load the maps package:
    > library(maps)
  2. Plot the world map:
    > # with country boundaries
    > map("world")
    > # without country boundaries
    > map("world", interior=FALSE)
  3. Plot the world map with colors:
    > map("world", fill=TRUE, col=palette(rainbow(7)))
  4. Plot the map of a country:
    > # for most countries, we access the map as a region on the world map > map("world", "tanzania") > # some countries (Italy, France, USA) have dedicated maps that we can directly access by name > map("france") > ...

Get R: Recipes for Analysis, Visualization and Machine Learning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.