Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Names of the countries on the plot with rworldmap

Tags:

r

maps

rworldmap

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")
like image 670
Dima Sukhorukov Avatar asked Mar 17 '23 01:03

Dima Sukhorukov


1 Answers

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:

enter image description here

like image 95
Cath Avatar answered Mar 19 '23 14:03

Cath