使用R中的SF对象将比例更改为LAT/LONG

发布于 2025-01-22 15:54:20 字数 1075 浏览 1 评论 0原文

恐怕我只是无法弄清楚。我正在尝试使用县的集合来绘制各州/美国地区的地区; 这是一个示例文件(ak_test.csv)

数据取自urbn_map数据集territories_counties。我的理解是,此数据使用“简单功能”(sf)几何形状,因此所有多边形数据都存储在每个县级对象的几何列中。

这是我要绘制的代码:

g <- ggplot(ak_test)
g <- g + geom_sf(aes(geometry = geometry, fill = Region), 
                 color = "black", show.legend = FALSE)
g <- g + geom_sf_label_repel(aes(geometry = geometry, label = County))
g <- g + coord_sf()
g

这是输出: “错误的单位”

我不了解轴上的单元,但我希望它们在lat/long中 - 我认为这是目的coord_sf()函数的功能。我尝试添加X和Y限制(使用状态的大致边界),但是当我这样做时,图像从页面上掉落。

在其他情况下,输出似乎旋转/倾斜(请参阅俄勒冈州/爱达荷州/蒙大拿州的图像) - 我希望转换为lat/long。 net/5dq97.png“ rel =“ nofollow noreferrer”> “旋转状态”

I'm afraid I just cannot figure this out. I am trying to plot regions in states/US territories using collections of counties; here is an example file (AK_Test.csv).

The data is taken from the urbn_map data set territories_counties. It's my understanding that this data uses the "simple features" (sf) geometry, so all of the polygon data is stored in the geometry column for each county-level object.

Here is the code I am using to plot:

g <- ggplot(ak_test)
g <- g + geom_sf(aes(geometry = geometry, fill = Region), 
                 color = "black", show.legend = FALSE)
g <- g + geom_sf_label_repel(aes(geometry = geometry, label = County))
g <- g + coord_sf()
g

Here is the output: wrong units

I do not understand the units on the axes, but I would like them to be in lat/long -- I thought that was the purpose of the coord_sf() function. I've tried adding x and y limits (using the approximate boundaries of the state), but when I do that, the image falls off the page.

In other cases, the output appears rotated/tilted (see image with Oregon/Idaho/Montana) - I'm hoping that the conversion to lat/long addresses this as well.rotated states

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

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

发布评论

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

评论(1

软的没边 2025-01-29 15:54:20

这些数字是< / em>纬度 /经度,但它们与所需的坐标系统不同。您需要使用适当的CRS重新投影数据:

library(sf)
library(ggplot2)
library(ggrepel)

url <- "https://raw.githubusercontent.com/Doc-Midnight/Test_Dir/main/AK_Test2"

ak_test <- source(url)

ak_test <- ak_test$value

ak_test$geometry <- st_transform(ak_test$geometry, "WGS84")

g <- ggplot(ak_test)
g <- g + geom_sf(aes(geometry = geometry, fill = Region), 
                 color = "black", show.legend = FALSE)
g <- g + geom_sf_label(aes(geometry = geometry, label = County))
g + labs(x = "longitude", y = "latitude")

”在此处输入图像描述“

注意,我不知道geom_sf_label_repel来自哪里附带问题。

These numbers are latitude / longitude, but they are in a different co-ordinate system from the one you want. You need to re-project the data using an appropriate crs:

library(sf)
library(ggplot2)
library(ggrepel)

url <- "https://raw.githubusercontent.com/Doc-Midnight/Test_Dir/main/AK_Test2"

ak_test <- source(url)

ak_test <- ak_test$value

ak_test$geometry <- st_transform(ak_test$geometry, "WGS84")

g <- ggplot(ak_test)
g <- g + geom_sf(aes(geometry = geometry, fill = Region), 
                 color = "black", show.legend = FALSE)
g <- g + geom_sf_label(aes(geometry = geometry, label = County))
g + labs(x = "longitude", y = "latitude")

enter image description here

Note, I have no idea where geom_sf_label_repel comes from, so I have used non-repeling labels since they are incidental to the question.

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