R ggplot2 карта Латинской Америки - PullRequest
2 голосов
/ 19 июня 2020

Я новичок в RStudio и пытаюсь создать карту Латинской Америки в формате ggplot. Кажется, я не могу правильно наложить карту. Я включил картинку в конце полученного результата. Я не уверен, что делаю не так. Любая помощь приветствуется.


constructed <- rejoined %>%
    mutate(group = cut(Case.Fatality_Ratio, 
                  breaks = c(0, 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, Inf), 
                  labels = c(0, 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20),
                  include.lowest=TRUE))

> dput(head(constructed))
structure(list(Country_Region = c("Argentina", "Bahamas", "Barbados", 
"Belize", "Brazil", "Brazil"), geometry = structure(list(structure(c(-38.4161, 
-63.6167), class = c("XY", "POINT", "sfg")), structure(c(25.025885, 
-78.035889), class = c("XY", "POINT", "sfg")), structure(c(13.1939, 
-59.5432), class = c("XY", "POINT", "sfg")), structure(c(17.1899, 
-88.4976), class = c("XY", "POINT", "sfg")), structure(c(-9.0238, 
-70.812), class = c("XY", "POINT", "sfg")), structure(c(-9.0238, 
-70.812), class = c("XY", "POINT", "sfg"))), class = c("sfc_POINT", 
"sfc"), precision = 0, bbox = structure(c(xmin = -38.4161, ymin = -88.4976, 
xmax = 25.025885, ymax = -59.5432), class = "bbox"), crs = structure(list(
    input = "EPSG:4326", wkt = "GEOGCS[\"WGS 84\",\n    DATUM[\"WGS_1984\",\n        SPHEROID[\"WGS 84\",6378137,298.257223563,\n            AUTHORITY[\"EPSG\",\"7030\"]],\n        AUTHORITY[\"EPSG\",\"6326\"]],\n    PRIMEM[\"Greenwich\",0,\n        AUTHORITY[\"EPSG\",\"8901\"]],\n    UNIT[\"degree\",0.0174532925199433,\n        AUTHORITY[\"EPSG\",\"9122\"]],\n    AUTHORITY[\"EPSG\",\"4326\"]]"), class = "crs"), n_empty = 0L), 
    Case.Fatality_Ratio = c(2.63799600975393, 10.6796116504854, 
    7.29166666666667, 10, 2.68616469612114, 3.35150231992432), 
    Incidence_Rate = c(69.8671471009338, 26.1921230368622, 33.4062936065226, 
    5.02991542197218, 1093.27784927461, 665.167076821569), group = structure(c(3L, 
    7L, 5L, 6L, 3L, 3L), .Label = c("0", "1", "2", "4", "6", 
    "8", "10", "12", "14", "16", "18", "20"), class = "factor")), row.names = c(NA, 
-6L), na.action = structure(c(`47` = 47L, `79` = 79L, `155` = 155L
), class = "omit"), sf_column = "geometry", agr = structure(c(Country_Region = NA_integer_, 
Case.Fatality_Ratio = NA_integer_, Incidence_Rate = NA_integer_, 
group = NA_integer_), .Label = c("constant", "aggregate", "identity"
), class = "factor"), class = c("sf", "tbl_df", "tbl", "data.frame"))

library(sf)

ggplot(constructed) +
  geom_sf(aes(fill = group), color = "white", size=.1) +
  geom_sf(data= gps_object, fill=NA, color="white", size=.3) +
      scale_fill_viridis_d(option = "viridis", drop=FALSE) +
      labs(title = "Case Fatality Ratio of COVID-19 (per 100,000):",
           subtitle = 'June 14, 2020',
           caption = "Data: Center for System Science and Engineering (CSSE) at John Hopkins University, https://github.com/CSSEGISandData/COVID-19",
           x="",
           y="") +
       coord_sf(crs = "+proj=lcc +lat_1=-5 +lat_2=-42 +lat_0=-32 +lon_0=-60 +x_0=0 +y_0=0 +ellps=aust_SA +units=m +no_defs",
               datum=NA) +
      theme_minimal() + 
      theme(panel.background = element_rect(fill = 'black'),
            plot.title.position = "plot",
            plot.title = element_text(size=20,
                                      face="bold"),
            plot.subtitle = element_text(size=15),
            plot.caption = element_text(size=10),
            legend.position = "top",
            legend.box = "horizontal",
            legend.title = element_blank(),
            legend.justification='left') +
      guides(fill = guide_legend(nrow = 1))

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...