简体   繁体   中英

Plot islands as dots on world map

I'm using rworldmap to create a world map to show data. For my data, the small island states are quite important, but they are too small to see when the entire world is shown. So I'd like to have a small visible dot/circle at the location of the island nations in the color of the appropriate category instead. I looked around, but didn't find a solutions for this. Of course I could do this manually for every island nation. My question is, is there a quicker solution?

As an example, here is the standard example for plotting data (in this case biodiversity) which comes with the rworldmap package. How could I, in this map, show the island nations? Any suggestion would be appreciated!

library(rworldmap)
mapCountryData()
data("countryExData",envir=environment(),package="rworldmap")
sPDF <- joinCountryData2Map(countryExData
              , joinCode = "ISO3"
              , nameJoinColumn = "ISO3V10"
              )
mapCountryData( sPDF
              , nameColumnToPlot="BIODIVERSITY" 
              )

Thanks to lmo for pointing me in the right direction, I now found a solution. I'll provide the answer here including a reproducible example. I also think I have to explain one extra bit of the question I didn't make clear enough. I want all countries of the world to be plotted to get a world map. Then, I want to add extra dots for the island countries to make them visible. The solution I found was to first plot the normal world map, and then to add a second map to the first plot, but only for the selected island nations as suggested by lmo .

To start out, here is the code again to produce the basic plot

par(mar=c(0,0,1,0))
data("countryExData",envir=environment(),package="rworldmap")
sPDF <- joinCountryData2Map(countryExData, joinCode = "ISO3", nameJoinColumn = "ISO3V10")
mapCountryData( sPDF, nameColumnToPlot="BIODIVERSITY", catMethod="fixedWidth")

Here, the islands are not visible, they are simply too small. Now I have to generate the dataset for only these island nations. They are not in the dataset, so just to demonstrate what I want to do, I selected a few island countries and reused some data from the other dataset. So the data are not actual data here.

mapdata2 <- data.frame(ccode=c("ATG", "COM", "CPV", "DMA", "FJI", "FSM",
     "GRD", "KIR", "KNA", "LCA", "MDV", "MHL", "MUS", "NRU","PLW", "SLB", 
     "STP", "SYC", "TON", "TUV", "VCT", "VUT", "WSM"), 
     biodiv=countryExData$BIODIVERSITY[1:23], size=1)

The size variable at the end is needed so that all island points will have the same size. Now I can use the mapBubbles command to add the dots for the selected island nations to the original plot as follows.

sPDF2 <- joinCountryData2Map(mapdata2, joinCode = "ISO3", nameJoinColumn = "ccode")
mapBubbles(sPDF2,nameZSize='size', nameZColour='biodiv',add = T, 
     addColourLegend = F, addLegend = F, pch=21, symbolSize=.22,catMethod="fixedWidth")

This produced the map below. Probably there are better or faster ways, but I'm pretty happy with the result now. Of course colours, symbol size, etc. can now be changed...

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM