使用 rworldmap 添加点以表示世界地图上的城市
Adding points to represent cities on a World Map using rworldmap
我想制作一张填有特定国家/地区的世界地图,但如果可能的话,我还想包括代表这些国家/地区特定城市的精确定位点。
我一直在使用 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))
我想要突出显示已填写国家/地区中的城市的具体点。
I'd like to have specific points highlighting cities on the filled in
countries.
那么mapBubbles()
就是错误的函数。您可以像在常规 R-plot.
中一样添加 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
可能也是更好的选择。
编辑: 要相应地使用您提供的城市 select:
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"))
我想制作一张填有特定国家/地区的世界地图,但如果可能的话,我还想包括代表这些国家/地区特定城市的精确定位点。
我一直在使用 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))
我想要突出显示已填写国家/地区中的城市的具体点。
I'd like to have specific points highlighting cities on the filled in countries.
那么mapBubbles()
就是错误的函数。您可以像在常规 R-plot.
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
可能也是更好的选择。
编辑: 要相应地使用您提供的城市 select:
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"))