简体   繁体   中英

Plot pre-1990 world map in R

I am working with some global data from before 1991, so before the USSR, Yugoslavia and Czechoslovakia split up. I would like to plot the data using rworldmap or maps, but the package appears to only have the modern world map easily accessible. All the pre-1991 countries show up blank and with the boundaries dividing their post-1991 counterparts.

This code produces the historical map:

if (requireNamespace("mapdata", quietly=TRUE) && packageVersion("mapdata") >= "2.3")
 {map("mapdata::worldLores", fill = TRUE, col = 1:10)}

EDIT : also, as per the helpful comment below, a historical map shapefile is easily obtained from:

library(cshapes)
cshp.data<-cshp(as.Date("1990-01-01"))
plot(cshp.data)

But I cannot figure out if it is possible to combine this with the rworldmap functions ... or if I will have to figure out how to use the maps package, which seems to work differently. (Or maybe there is a ggplot solution?)

The rworldmap code I use currently (to get the modern map) is:

#make example data including Soviet Union
country <- as.vector(c("Afghanistan","Australia","Iceland","Soviet Union", 
"Zimbabwe"))
value <- as.vector(c(5,10,100,10,50))
df<-data.frame(country,value)

#make map
map1 <- joinCountryData2Map(df, joinCode = "NAME", nameJoinColumn = 
"country")
mapCountryData( map1, addLegend=F, catMethod="fixedWidth", 
nameColumnToPlot="value" )
#...Soviet Union is blank

Ahah, there is a ggplot solution using the old map from the mapdata package:

library(ggplot2)
library(dplyr)
library(mapdata)

df<-data.frame(country=c("Afghanistan","Australia","Iceland","USSR","Zimbabwe"),
           value=c(5,10,100,10,50),stringsAsFactors=FALSE)

WorldData <- map_data('worldLores') #use the old map
WorldData <- fortify(WorldData)

mapped <- ggplot() +
  geom_map(data=WorldData, map=WorldData,
              aes(x=long, y=lat, group=group, map_id=region),
              fill="white", colour="#7f7f7f", size=0.5) +
  geom_map(data=df, map=WorldData,
              aes(fill=value, map_id=country),
              colour="#7f7f7f", size=0.5)
mapped

(mapping code borrowed from this post, cheers @hrbrmstr)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM