在R中插入标签和zoon

发布于 2025-02-12 10:15:20 字数 1734 浏览 1 评论 0原文

我想帮助下图中的两件事:

1-在图表的点中,我也想拥有相应的属性编号。

2-是否有可能使点的可视化更接近?

下面可执行的代码:

library(rgdal)
library(sf)
library(raster)
library(dplyr)

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)
shp_subset <- shp[shp$NM_MUNICIP == "CASTRO",]

#Points
Points_properties<-structure(list(Propertie = c(1,2,3,4,5), Latitude = c(-24.781624, -24.775017, -24.769196, 
 -24.761741, -24.752019), Longitude = c(-49.937369, 
-49.950576, -49.927608, -49.92762, -49.920608)), row.names = c(NA, -5L), class = c("tbl_df", "tbl", 
"data.frame"))

#Generate map

marsize <- .2
par(mar = rep(marsize,4))
z <- .4
shp_subset_cropped <- raster::crop(shp_subset,
                                   extent(c(
                                     (extent(shp_subset)@"xmin"*(1-z)+z*min(Points_properties$Longitude)),
                                     (extent(shp_subset)@"xmax"*(1-z)+z*max(Points_properties$Longitude)),
                                     (extent(shp_subset)@"ymin"*(1-z)+z*min(Points_properties$Latitude)),
                                     (extent(shp_subset)@"ymax"*(1-z)+z*max(Points_properties$Latitude))
                                   )))
plot(shp_subset_cropped)

points(x = Points_properties$Longitude,
       y= Points_properties$Latitude, col = "black",pch = 16,cex=1)

“在此处输入图像描述”

I would like help on two things in the graph below:

1 - In the points of the graph, I would like to have the corresponding property number as well.

2 - Is it possible to bring the visualization of the points even closer?

Executable code below:

library(rgdal)
library(sf)
library(raster)
library(dplyr)

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)
shp_subset <- shp[shp$NM_MUNICIP == "CASTRO",]

#Points
Points_properties<-structure(list(Propertie = c(1,2,3,4,5), Latitude = c(-24.781624, -24.775017, -24.769196, 
 -24.761741, -24.752019), Longitude = c(-49.937369, 
-49.950576, -49.927608, -49.92762, -49.920608)), row.names = c(NA, -5L), class = c("tbl_df", "tbl", 
"data.frame"))

#Generate map

marsize <- .2
par(mar = rep(marsize,4))
z <- .4
shp_subset_cropped <- raster::crop(shp_subset,
                                   extent(c(
                                     (extent(shp_subset)@"xmin"*(1-z)+z*min(Points_properties$Longitude)),
                                     (extent(shp_subset)@"xmax"*(1-z)+z*max(Points_properties$Longitude)),
                                     (extent(shp_subset)@"ymin"*(1-z)+z*min(Points_properties$Latitude)),
                                     (extent(shp_subset)@"ymax"*(1-z)+z*max(Points_properties$Latitude))
                                   )))
plot(shp_subset_cropped)

points(x = Points_properties$Longitude,
       y= Points_properties$Latitude, col = "black",pch = 16,cex=1)

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的呼吸 2025-02-19 10:15:20

示例数据

Points_properties <- data.frame(Propertie = c(1,2,3,4,5), Latitude = c(-24.781624, -24.775017, -24.769196, 
 -24.761741, -24.752019), Longitude = c(-49.937369, 
-49.950576, -49.927608, -49.92762, -49.920608))

library(terra)
v <- vect(Points_properties, c("Longitude", "Latitude"))

# simple example polygon, to avoid the need for downloads
m <- matrix(c(-49.986, -49.861, -49.866, -50.029, -24.673, -24.728, -24.832, -24.797), ncol=2)
p <- vect(m, "polygons")

首先绘制点。您可以使用“ EXT”参数扩展映射的区域(或Xlim和Ylim);然后使用文本

plot(v, ext=ext(v) + .05)
text(v, v$Propertie, pos=4)
lines(p)

您还可以绘制标签而不是点:

plot(v, ext=ext(v) + .05, cex=0)
text(v, v$Propertie)

Example data

Points_properties <- data.frame(Propertie = c(1,2,3,4,5), Latitude = c(-24.781624, -24.775017, -24.769196, 
 -24.761741, -24.752019), Longitude = c(-49.937369, 
-49.950576, -49.927608, -49.92762, -49.920608))

library(terra)
v <- vect(Points_properties, c("Longitude", "Latitude"))

# simple example polygon, to avoid the need for downloads
m <- matrix(c(-49.986, -49.861, -49.866, -50.029, -24.673, -24.728, -24.832, -24.797), ncol=2)
p <- vect(m, "polygons")

Plot the points first. You can use the "ext" argument to expand the area mapped (or xlim and ylim); and then use text.

plot(v, ext=ext(v) + .05)
text(v, v$Propertie, pos=4)
lines(p)

You can also plot the labels instead of the points:

plot(v, ext=ext(v) + .05, cex=0)
text(v, v$Propertie)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文