在R中插入标签和zoon
我想帮助下图中的两件事:
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
示例数据
首先绘制点。您可以使用“ EXT”参数扩展映射的区域(或Xlim和Ylim);然后使用
文本
。您还可以绘制标签而不是点:
Example data
Plot the points first. You can use the "ext" argument to expand the area mapped (or xlim and ylim); and then use
text
.You can also plot the labels instead of the points: