简体   繁体   English

在世界地图上将岛屿绘制为点

[英]Plot islands as dots on world map

I'm using rworldmap to create a world map to show data. 我正在使用rworldmap创建一个世界地图以显示数据。 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. 作为示例,这是rworldmap软件包随附的用于绘制数据(在本例中为生物多样性)的标准示例。 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. 感谢lmo为我指明了正确的方向,现在我找到了解决方案。 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 . 我发现的解决方案是首先绘制法线世界地图,然后将第二张地图添加到第一张地图,但仅适用于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. 最后需要size变量,以便所有孤岛点都具有相同的大小。 Now I can use the mapBubbles command to add the dots for the selected island nations to the original plot as follows. 现在,我可以使用mapBubbles命令将所选岛国的点添加到原始图中,如下所示。

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... 当然,颜色,符号大小等都可以更改了。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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