I wanted to make a map of the locations in the world were some bacterial isolates were collected. I found a nice website that gave me some useful location on plotting maps in R.
Here's what I found worked for me.
First I got a map of the world:
Then I made a text file in which I had the number of bacterial isolates collected in each country, and the abbreviation for countries using the ISO_A3 three-letter codes:
1 Bahrain BHR
1 Ecuador ECU
1 El Salvador SLV
1 Gabon GAB
1 Guatemala GTM
isolatecounts <- numeric()
for (i in 1:numcountries)
{
mycountry <- world$iso_a3[i]
print(paste("Calculating for country=",mycountry," row i=",i, "mylength=",length(isolatecounts)))
myindex <- which(mycountry == MyCountryCountData$Country.Code)
if (length(myindex) > 0)
{
myisolates <- MyCountryCountData$Isolates[myindex]
isolatecounts <- append(isolatecounts, myisolates, after=length(isolatecounts))
}
else
{
isolatecounts <- append(isolatecounts, 0, after=length(isolatecounts))
}
}
> tiff("countries_histogram.tiff", units="in", width=5, height=5, res=300)
> ggplot(data = world) + geom_sf(aes(fill = isolatecounts[1:242])) + scale_fill_viridis_c(option = "plasma", trans="sqrt")
> dev.off()

