美国边界线不会被添加到散布的美国地区的geom_map地图中 [英] US border line is not added to geom_map maps of dispersed US regions
问题描述
我试过geom_polygon()和geom_maps()。没有不同。这是什么原因,以及如何解决它?
非常感谢您的帮助!
所以,问题在于预测的差异。美国地图是在UTM系统中,以米和东经和北纬为单位,但以长和经纬度命名。而美国地图处于经纬度协调系统。我在代码中的fortify行之前转换了形状,如下所示:
library(ggplot2)
library(tidyverse)
usa< - map_data(usa,)
shape< - spTransform(shape,CRS(+ proj = longlat (形状,区域=名称)
colnames(shape_map)< - c(long,lat,+ datum = WGS84))
shape_map< - fortify order,hole,piece,region,group)
prop.test< - proptest.result [which(proptest.result $ variable ==Upward N ),]
ggplot()+
geom_map(
data = usa,map = usa,aes(long,lat,map_id = region),
color =#2b2b2b,fill =#00000000
)+
geom_map(
data = shape_map,map = shape_map,
aes(long,lat,map_id = region)
)+
geom_map(
data = filter(prop.test,season ==DJF),
map = shape_map,aes(fill = prop.mega,map_id = megaregion)
)+
viridis :: scale_fill_viridis(direction = -1)+
coord_map(polyconic)+
ggth emes :: theme_map()
这是结果图:
I have a map of dispersed parts in the Us. This is in the following question (that contains link to the data):
mapping by ggplot2 geom_polygon goes crazy after merging data
It was answered very well. Then I tried to add the US border line, therefore I added the geom_path to the answered code,but no result, it creates the same map just containing the dispersed areas.
library(ggplot2)
#library(tidyverse)
library(dplyr)
library(maps)
load("./data.rda")
usa <- map_data("usa")
shape_map <- tbl_df(fortify(shape, region="Name"))
colnames(shape_map) <- c("long", "lat", "order", "hole", "piece", "region", "group")
ggplot() +
geom_path(data = usa, aes(long, lat, group=group))+
geom_map(data=shape_map, map=shape_map, aes(long, lat, map_id=region)) +
geom_map(
data=filter(prop.test, season=="DJF"),
map=shape_map, aes(fill=prop.mega, map_id=megaregion)
)
I have tried geom_polygon() and geom_maps(). no difference. What's the reason, and how can it be solved?
Thank you so much for your help!
So, the problem was the differences in the projections. The us map was in a UTM system, giving Easting and Northing in meters, but named as long and lat. while the US map was in a lat/lon coordinating system. I transformed the shape just before the fortify line in the code as below:
library(ggplot2)
library(tidyverse)
usa <- map_data("usa", )
shape <- spTransform(shape, CRS("+proj=longlat +datum=WGS84"))
shape_map <- fortify(shape, region="Name")
colnames(shape_map) <- c("long", "lat", "order", "hole", "piece", "region", "group")
prop.test <- proptest.result[which(proptest.result$variable=="Upward N"),]
ggplot() +
geom_map(
data=usa, map=usa, aes(long, lat, map_id=region),
color="#2b2b2b", fill="#00000000"
) +
geom_map(
data=shape_map, map=shape_map,
aes(long, lat, map_id=region)
) +
geom_map(
data=filter(prop.test, season=="DJF"),
map=shape_map, aes(fill=prop.mega, map_id=megaregion)
) +
viridis::scale_fill_viridis(direction=-1) +
coord_map("polyconic") +
ggthemes::theme_map()
and this is the resulted map:
这篇关于美国边界线不会被添加到散布的美国地区的geom_map地图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!