简体   繁体   English

r - 如何给地图/土地区域着色,给定2个类别的点?

[英]r - How to color map/land areas, given points of 2 categories?

I'm going to create a map of the Papuan/Austronesian language distribution similar to this in R.我将创建一个类似于R的巴布亚语/南岛语分布的 map。

To do so, I collected the geo-references of languages listed in transnewguinea.org and in the Austronesian Basic Vocabulary Database , as well as their classification as being either Austronesian or Papuan.为此,我收集了transnewguinea.org南岛语基本词汇数据库中列出的语言的地理参考,以及它们被分类为南岛语或巴布亚语的分类。 This data can be plotted easily on a map as colored points:该数据可以在 map 上轻松绘制为彩色点:

data <- data.frame(lat = c(-16.6098, -4.6236, -7.56399200553307, -21.0735, -2.13, -2.76, 
                           -2.55, -3.79, -8.71919, -3.63, -16.4952, -3.4004, -8.42, 9.76831962330826, 
                           -8.38543101556771, -8.7257, -0.14316066226984, -3.8, -5.9164, 
                           5, -5, -8.57966283377484, -7.74, -21.6524, -6.47, -16.5499, -4.67, 
                           -4.48607103437042, -2.2555, -3.57785, 5.3, -6.26, -10.0734060631886, 
                           -8, -8.62273552315168, -9.23, -4.8008, -16.4687, -3.7, -10.15, 
                           -15.9914, -7.4778, -6.19, -4.45, -5.52, -0.95, -9.616667, 7.33, 
                           -8.58405, -15.8559, -15.9914, -2.69797689175062, -9.40571004160002, 
                           -10.0734060631886, -4.67, -7.29, -6.67, -5.52851052569279, -15.633, 
                           -6.3153, -8.09, -8.66791800236312, -3.67, -8.67606354930773, 
                           -8.37, -16.0903, -4.46, -3.82, -6.66733557666654, -16.0095, -16.4582, 
                           -8.17, -5.83, -14.9738, -15.9813, -1.78, -8.28444635517256, -1.917, 
                           -7.75, -16.4339, -10.22, 5.333333, -16.0903, -19.5303, -16.8979, 
                           -2.37, 2.30925, 1.05, -4.3, -4.05, -1.5297, -15.3498, -4.696879026, 
                           -9.06, -2.1143, -5.89078468421825, -8.932, -3.33, -4.5, -1.09129174695414),
                   lon = c(168.171, 121.824, 127.41943359375, 164.869, 132.45, 132.06, 
                           136.69, 140.2, 117.47199, 140.77, 167.78, 154.731, 160.58, 119.569541928441, 
                           162.740478515625, 151.072, 128.487258649535, 142.3, 146.859, 
                           116, 143.89, 125.619226658682, 139.27, 165.578, 143.5, 167.509, 
                           146, 154.215087890625, 121.035, 128.31046, 163, 145.73, 120.702381123445, 
                           147.23, 149.827019548963, 148.45, 105.33909, 167.4961, 142.02, 
                           148.45, 167.288, 178.69192, 147.58, 151.7, 144.12, 135.88, 161.45, 
                           149.33, 157.29578, 168.189, 167.288, 104.915771372616, 119.6630859375, 
                           120.702381123445, 143.85, 142.64, 139.25, 148.677978515625, 166.9525, 
                           130.01495, 127.2, 116.279296875, 142.68, 121.835632324219, 138.07, 
                           167.239, 143.06, 141.34, 147.513427734375, 167.3464, 167.6396, 
                           128, 132.92, 168.12, 167.208, 132.31, 129.917695058198, 146.887, 
                           156.666667, 167.566, 166.22, 132.25, 167.239, 170.215, 168.569, 
                           139.75, 128.15277, 154.75, 143.32, 141.42, 145.074, 166.891, 
                           121.607666015625, 159.12, 146.627, 155.211915129668, 146.749, 
                           134.88, 140.44, 172.110425708816),
                   lang = structure(c(1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 
                                      1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 
                                      1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 
                                      1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 
                                      1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 
                                      1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 
                                      2L, 1L, 1L, 1L, 1L, 2L, 1L), .Label = c("Austronesian", "Papuan"
                                      ), class = "factor")
)

require(maps)
map("world2", xlim=c(120,200), ylim=c(-25,10), fill=T, col="gray")
points(data$lon, data$lat, col=data$lang, pch=16)

In the code above I just gave a sample of 100 language records.在上面的代码中,我只是给出了 100 条语言记录的样本。 Nevertheless, the original database is much bigger (cf. attached image for a plot of all language samples from the region under consideration):尽管如此,原始数据库要大得多(参见所考虑区域中所有语言样本的 plot 的附加图像):

在此处输入图像描述

However, I wonder how I can estimate approximate regions of language groups based on the spatial sample distributions and how I can plot these estimated language regions as colored areas onto the map.但是,我想知道如何根据空间样本分布估计语言组的近似区域,以及如何将这些估计的语言区域作为彩色区域添加到 map 上。

Any help is appreciated!任何帮助表示赞赏! Thanks a lot in advance!提前非常感谢!

The suggestion of @jazzurro was nice. @jazzurro 的建议很好。 However, I didn't succeed after many trials.但是,经过多次尝试,我没有成功。 However, I found the first steps to another solutions.但是,我找到了另一个解决方案的第一步。 It is pretty simple and basically uses Voronoi polygons to color the map regions:它非常简单,基本上使用 Voronoi 多边形为 map 区域着色:

map("world2", xlim=c(120,200), ylim=c(-25,10), fill=T, col="gray")

require(deldir)
delaunay <- deldir(data$lon, data$lat)
tiles <- tile.list(delaunay)
Col <- ifelse(data$lang=="Austronesian", "blue", "red")
for (i in 1:length(tiles)) {
  polygon(tiles[[i]], col=Col[i], border=NA)
}

map("world2", xlim=c(120,200), ylim=c(-25,10), bg="white", add=T)

However, I learnt that the bg parameter in the map command just changes the color of the par background and not the color of the sea regions in the map.但是,我了解到map命令中的bg参数只是更改了par背景的颜色,而不是 map 中海域的颜色。

Thus, I wonder if anybody knows how I can create a polygon of the non-land regions of the map to hide the colored polygons at sea areas (I want them to be white)???因此,我想知道是否有人知道我如何创建 map 的非陆地区域的多边形来隐藏海域的彩色多边形(我希望它们是白色的)???

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

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