簡體   English   中英

如何在R中的地圖上插入點

[英]How to insert points on a map in R

下面的代碼生成一個特定國家的地圖。 但是,我想在這個生成的地圖中插入一些屬性的點。 為此,我插入了屬性的坐標。

Points_properties = structure (list(Properties=c(1,2,3,4,5,6), Latitude = c(-24.930473, -24.95575,-24.924161,-24.95579, -24.94557, -24.93267),
Longitude = c(-49.994889, -49.990162,-50.004343, -50.007371, -50.01542, -50.00702)), row.names=c(NA,6L), class="data.frame")

> Points_properties
  Properties  Latitude Longitude
1          1 -24.93047 -49.99489
2          2 -24.95575 -49.99016
3          3 -24.92416 -50.00434
4          4 -24.95579 -50.00737
5          5 -24.94557 -50.01542
6          6 -24.93267 -50.00702

可執行代碼如下:

library(rgdal)

temp <- tempfile()
temp2 <- tempfile()
download.file("https://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2015/UFs/PR/pr_municipios.zip",temp)

unzip(zipfile = temp, exdir = temp2)
shp <- readOGR(temp2)

plot(shp)

在此處輸入圖像描述

有許多庫允許您向圖形添加點。

因為在您的示例中您的值非常接近,所以看起來像繪制了一個點。

在基礎 R 中:

plot(shp)

points(x = Points_properties$Longitude, y= Points_properties$Latitude, col = "red")

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM