我想制作一张填有特定国家/地区的世界地图,但如果可能的话,我还要包括代表这些国家/地区中特定城市的精确点。
我一直在使用rworldmap
软件包并与其他人进行实验,但是我很难理解如何确定特定的城市位置以及在哪里包括mapbubbles
。 >
也许我可以添加一条代表圣地亚哥的行,但我不知道它将去哪里:
mapBubbles(dF="CEAMap", nameX = "-117.16", nameY = "32.71", nameZSize = "CEAMap",)
我一直在阅读开发人员的PDF,老实说我真的不明白如何实现地图气泡以及像nameZsize这样的东西应该包含在什么地方。
我使用本指南来学习如何突出显示国家/地区,但是就精确定位城市而言,我似乎是一个人,因为我无法真正理解开发人员的PDF。 How to create a world map in R with specific countries filled in?
到目前为止,这是我的完整代码:
library(rworldmap)
library(ggmap)
library(maptools)
library(maps)
theCountries <- c("USA",
"CAN", "DEU", "FRA", "IND",
"GBR", "NLD", "ITA",
"CHN", "KOR", "JPN",
"ESP", "PRT", "RUS",
"NOR", "SGP", "AUS",
"CHL", "MEX", "PHL", "RWA",
"JOR", "HND", "PAN", "THA", "DOM",
"ZAF", "TUR", "CHE", "FIN",
"SEN", "BOL", "OMN", "PAK", "CMR", "MUS", "BEL", "MYS",
"UAE", "BRA", "MLI", "MOZ", "NAM", "EGY", "ARG", "UKR", "ZMB", "KEN",
"VNM", "NGA", "DNK", "IRN", "AFG")
# These are the ISO3 names of the countries you'd like to plot in red
CEAMap <- data.frame(country = c("USA",
"CAN", "DEU", "FRA", "IND",
"GBR", "NLD", "ITA",
"CHN", "KOR", "JPN",
"ESP", "PRT", "RUS",
"NOR", "SGP", "AUS",
"CHL", "MEX", "PHL", "RWA",
"JOR", "HND", "PAN", "THA", "DOM",
"ZAF", "TUR", "CHE", "FIN",
"SEN", "BOL", "OMN", "PAK", "CMR", "MUS", "BEL", "MYS",
"UAE", "BRA", "MLI", "MOZ", "NAM", "EGY", "ARG", "UKR", "ZMB", "KEN",
"VNM", "NGA", "DNK", "IRN", "AFG"),
involvement = c(1,
2, 2, 2, 2,
3, 3, 3,
4, 4, 4,
5, 5, 5,
6, 6, 6,
7, 7, 7, 7,
8, 8, 8, 8, 8,
9, 9, 9, 9,
10, 10, 10, 10, 10, 10, 10, 10,
11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
12, 12, 12, 12, 12))
# CEAMap is a data.frame with the ISO3 country names plus a variable to
# merge to the map data
CEAcountries <- joinCountryData2Map(CEAMap, joinCode = "ISO3",
nameJoinColumn = "country")
# This will join your CEAMap data.frame to the country map data
mapCountryData(CEAcountries, nameColumnToPlot="country",
catMethod = "categorical",
mapTitle='CEA Locations',
missingCountryCol = gray(.8))
我想在强调的国家/地区中突出显示城市。
答案 0 :(得分:0)
我想在填写的内容上突出显示城市 国家。
然后mapBubbles()
是错误的函数。您可以像在常规R图中一样添加points()
。
获取之前城市的位置数据:
library(maps)
data("world.cities")
plotcities <- subset(world.cities, capital == 1)
我不知道您对哪个城市感兴趣,所以我只带了首都
mapCountryData(CEAcountries, nameColumnToPlot="country",
catMethod = "categorical",
mapTitle='CEA Locations',
missingCountryCol = gray(.8), addLegend = FALSE)
points(plotcities$long, plotcities$lat, pch = 18, col = "black")
尽管如此,我还是建议您查看诸如tmap
之类的软件包。他们制作了更好的地图。 ggplot2
也可能是更好的选择。
编辑:要使用您提供的城市,只需进行相应选择:
plotcities <- subset(world.cities,
name %in% c("Cologne", "Chennai", "Denver", "Madrid", "Manila", "San Diego", "Seattle", "Shanghai")
& country.etc %in% c("Germany", "USA", "Spain", "China", "Philippines", "India"))