mWorldMap: Make a world map with 'ggplot2'

Description Usage Arguments Examples

View source: R/maps2.R

Description

mWorldMap takes in one dataframe that includes information about different countries. It merges this dataframe with a dataframe that includes geographical coordinate information. Depending on the arguments passed, it returns this data or a ggplot object constructed with the data.

Usage

1
2
mWorldMap(data = NULL, key = NA, fill = NULL, plot = c("borders",
  "frame", "none"))

Arguments

data

A dataframe with countries as cases

key

The column name in the data that holds the unique names of each country

fill

A variable in the data used to specify the fill color of countries in the map (note: if fill is not null, then plot cannot be set to "none")

plot

The plot desired for the output. plot = "none" returns the merged data that is the result of merging the data and the dataframe with the geographical coordinate information; plot = "frame" returns an empty (unplottable) ggplot object; plot = "border" (the default) returns a ggplot object with one geom_polygon layer that shows the borders of the countries

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Not run: 
gdpData <- CIAdata("GDP")      # load some world data

mWorldMap(gdpData, key="country", fill="GDP")

gdpData <- gdpData %>% mutate(GDP5 = ntiles(-GDP, 5, format="rank")) 
mWorldMap(gdpData, key="country", fill="GDP5")

mWorldMap(gdpData, key="country", plot="frame") +
geom_point()

mergedData <- mWorldMap(gdpData, key="country", plot="none")

ggplot(mergedData, aes(x=long, y=lat, group=group, order=order)) +
geom_polygon(aes(fill=GDP5), color="gray70", size=.5) + guides(fill=FALSE)  

## End(Not run)

mosaic documentation built on Aug. 27, 2017, 1:03 a.m.