问题描述
早上好,我花了很多时间来弄清楚如何直接在情节上添加国家名称,而不是像传说的一部分,而是像地图的一部分.我正在使用rworldmap软件包,尝试使用 identifyCountries()
-但它可以进行交互(当用户单击地图时),比我发现的解决方案还好具有ggmap和ggplot2的国家/地区的行政区域地图但这是用于ggplot2的,而且太复杂了.我试图用 mapCountryData()
做到这一点.希望对您有所帮助,谢谢.
Good morning, I have spent a lot of time to figure out how can I add a country names directly on plot not like a part of legend, but like part of map.Im using package rworldmap, tried to use identifyCountries ()
- but it something for interaction (when a user clicks on the map), than I have found a such solutionAdministrative regions map of a country with ggmap and ggplot2 but it's for ggplot2, and too complicated. Im trying to do it with mapCountryData()
. Hope for your help, thanks.
data <- data.frame(Country=c('Russia','Cyprus', 'Belize', 'Austria' ,'Virgin Islands',
'Italy','United States' ,'United Kingdom', 'Germany', 'France' ,'Poland' ,'Switzerland'),
Value=c(-0.310,-0.206,-0.300,-0.179,-0.196,-0.174,-0.105,-0.142,-0.082,-0.097,-0.027,0.052))
library('rworldmap')
pdf1 <- joinCountryData2Map(data, joinCode="NAME", nameJoinColumn="Country")
mapCountryData(pdf1, nameColumnToPlot="Value", catMethod="pretty",
colourPalette='white2Black',addLegend='TRUE',mapTitle=NULL, mapRegion="Europe")
推荐答案
您可以尝试:
# get the coordinates for each country
country_coord<-data.frame(coordinates(pdf1),stringsAsFactors=F)
# label the countries
text(x=country_coord$X1,y=country_coord$X2,labels=row.names(country_coord))
在代码之后传递这些行,您将获得:
passing these lines after your code, you'll get:
这篇关于带rworldmap的地块上的国家名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!