我已經使用choroplethr和choroplethrMaps包製作了地圖。我的問題是,爲了繪製一個國家,這個國家必須包含在choroplethrMaps包中包含的country.regions和country.map數據框中。 因此,可以說這是我的地圖如何使用choroplethr- choroplethr添加國家到country.map-country.region的choroplethr地圖 -
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.map(使用地圖包的地理編碼(「馬耳他」)功能)中添加country.regions及其緯度和經度的國家名稱,但它不會那樣工作