我已经使用 choroplethr 和 choroplethrMaps 包制作了地图。我的问题是,为了绘制一个 country ,这个 country 必须包含在 choroplethrMaps 包中包含的 country.regions 和 country.map 数据框中。所以可以说这是我的地图
install.packages("mapproj");library(mapproj)
install.packages("choroplethr")
install.packages("choroplethrMaps")
library(choroplethr);library(choroplethrMaps);library(ggplot2)
data(country.map)
data(country.regions)
a<-c(4.1,2.5,0.4,6.4,1.4,1.8,3.8,1.3,2.3,8.4,5.2,1.9,0.8,1.5,2.1,1.2,3.8,1.4,3.1,0.8,4.0,1.3,4.8,2.6,2.8,2.3,3.1,2.5,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA)
target<-c("austria","belgium","bulgaria","switzerland","cyprus","czech republic","denmark",
"estonia","spain","finland","france","greece","croatia","hungary","ireland","italy",
"lithuania","luxembourg","latvia","norway","poland","portugal","romania","sweden",
"slovenia","slovakia","turkey","united kingdom","russia","belarus","germany","ukraine","iceland"
,"netherlands","bosnia and herzegovina","albania","montenegro","macedonia","moldova","kosovo")
datas<-data.frame(region=target,value=a)
datas$region<-as.character(datas$region)
gg <- country_choropleth(datas,num_colors=1,zoom=target)
gg <- gg + xlim(-25.266001, 71.869301)
gg <- gg + ylim(34.536311, 70.008797)
gg <- gg + coord_map("lambert", lat0=27.636311, lat1=81.008797)
gg<-gg+scale_fill_continuous(name="%",low="yellow", high="orange", na.value="grey")
gg<-gg+theme(plot.background=element_rect(fill="dodgerblue",colour="black"),legend.position="bottom",legend.background = element_rect(),legend.text = element_text(size = 13, colour = "black"))
gg
一切都很好,因为我的数据框中的每个区域都包含在 country.regions 和 country.map 中具有相同的名称。
我的问题是我想将马耳他和塞尔维亚地区添加到我的地图中,我有这些地区的数据,但我不能这样做,因为它们不包含在 country.regions 和 country.map 数据框架中的开发人员中。我试过了将国家/地区名称添加到 country.regions 及其在 country.map 中的纬度和经度(使用 maps 包的 geocode("malta") 函数),但它不起作用