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 solution
Administrative 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")
You can try:
# 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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With