US border line not added to geom_map maps of scattered US regions

I have a map of the dispersed parts in Us. This is in the following question (which contains a link to the data):

mapping ggplot2 geom_polygon goes crazy after data merging

He answered very well. Then I tried to add the US border line, so I added geom_path to the answer to the code, but there is no result, it creates the same map that contains only distributed 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)
    )

Not displayed on border

I tried geom_polygon () and geom_maps (). no difference. What is the reason and how can this be solved?

Thank you so much for your help!

+4
source share
1 answer

, . UTM, Easting Northing , . lat/lon. , :

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()

:

enter image description here

+3

Source: https://habr.com/ru/post/1692800/


All Articles