问题
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)
I then plot it like so:
ggplot() +
geom_path(data = map_df, aes(x = long, y = lat, group = group)) +
labs(title = "ggplot map of pa counties")
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?
回答1:
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"))
来源:https://stackoverflow.com/questions/58172017/out-of-bounds-latitude-and-longitude-values-in-converted-shape-file-using-ggplot