O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

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

  1. Load the maps package:
> library(maps) 
  1. Plot the world map:
> # with country boundaries 
> map("world") 
> # without country boundaries 
> map("world", interior=FALSE) 
  1. Plot the world map with colors:
> map("world", fill=TRUE, col=palette(rainbow(7))) 
  1. 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") 
> map("italy")
  1. Plot a map of the USA:
> # with state boundaries > map("state") > # without state boundaries > map("state", interior = FALSE) > # with county boundaries > map("county") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required