使用ggplot在转换的形状文件中超出范围的纬度和经度值 [英] out of bounds latitude and longitude values in converted shape file using ggplot

查看:114
本文介绍了使用ggplot在转换的形状文件中超出范围的纬度和经度值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PA地理空间数据交换所.我读取了形状文件,然后将其转换为如下所示的数据框:

I'm trying to map the Pennyslvania counties using data from the PA Geospatial Data Clearinghouse. I read in the shape file and then convert it to a dataframe like so:

setwd(proj_path)
dsn <- "Data/PaCounty2019_07/PaCounty2019_07.shp"
map <- readOGR(dsn)
map_df <- tidy(map)

然后我像这样绘制它:

ggplot() +
geom_path(data = map_df, aes(x = long, y = lat, group = group)) +
labs(title = "ggplot map of pa counties")

这有效,但是经度/纬度很奇怪.纬度从-100,000到150,000,经度从-2e + 05到23 + 05.如果我尝试在地图上绘制任何点,则看起来它们都在[0,0],因为这些点的纬度和经度值当然都小于< 180. 此处的比例尺怪异的PA地图图像

This works, but the lat/long scale is very weird. Latitude goes from -100,000 to 150,000, and longitude goes from -2e+05 to 23+05. If I try to plot any points on the map, it looks like they're all at [0,0] because the latitude and longitude values for the points are of course all <180. Image of PA map with weird scale here

为什么秤如此扭曲?我该如何解决?

Why is the scale so distorted? How can I fix it?

推荐答案

您需要将shapefile转换为正常的经/纬投影.在定义map_df ...

You need to transform the shapefile to the normal lat/long projection. Do this before defining map_df...

map <- spTransform(map, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))

这篇关于使用ggplot在转换的形状文件中超出范围的纬度和经度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆