Как построить географические c точек на карте с разными цветами и легендами? - PullRequest
1 голос
/ 14 февраля 2020

Итак, у меня в настоящее время есть карта (она довольно уродливая, см. В приложении)

Map and points

Я нашел способ нанести их на вид сверху вниз, но я бы хотел прикрепите разные цвета и сделайте это в виде легенды (и, возможно, увеличения) вместо надписей в верхней части точек, как показано на первом рисунке. Кто-нибудь может мне с этим помочь? Вот идеальная картинка, но с легендой и разными цветами:

The ideal picture, but with a legend and different colours

#libraries

  library(readr)
  library(sp)
  library(rgdal)
  library(raster)
  library(GISTools)
  library(sf)

#col_coor points to be plotted
 SUB        POP      LON   LAT
   <chr>      <chr>  <dbl> <dbl>
 1 mandtii    AK    -156.   71.2
 2 ultimus    NU     -82.5  65.9
 3 ultimus    GR     -70.2  76.5
 4 arcticus   LB     -61.7  56.6
 5 arcticus   NF     -53.6  47.3
 6 arcticus   ST     -69.7  47.8
 7 arcticus   NS     -61.5  45.1
 8 arcticus   NB     -66.8  44.6
 9 arcticus   ME     -68.2  44.2
10 islandicus IC     -22.9  65.4
11 grylle     FI      19.3  60.2

# Convert Lat & Lon data into a SPDF            
col_loc <- sp::SpatialPointsDataFrame(col_coor[,3:4], col_coor)

# Assign a coordinate reference system 
crs(col_loc) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"

 radius <- 75000
  ColBuff<-raster::buffer(col_loc, width=(radius), filename='1000', doEdge=FALSE)


# Plot maximum flight radius polygons on base raster with continent boundaries
  data("wrld_simpl", package = "maptools")                                                                            
  world_map <- crop(wrld_simpl, extent(-180, 180, 35, 90))                                                                   
  plot(world_map, col="grey") 
  plot(ColBuff, pch=20, col="red",add=TRUE)

# Convert WGS84 to Arctic polar stereographic projection (STERE)  
  proj <- "+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.449 +units=m +no_defs"
  wm_stere <- spTransform(world_map, CRSobj = CRS(proj))
  plot(wm_stere, col="grey")
  cb_stere <- spTransform(ColBuff, CRSobj = CRS(proj))
  plot(cb_stere, pch=20, col="red",add=TRUE)

1 Ответ

1 голос
/ 14 февраля 2020

Я не уверен на 100%, что понимаю ваши вопросы, но вы хотите создать что-то подобное?

# packages
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(magrittr)
library(tmap)

# points data
col_coor <- data.frame(
  SUB = c(
    "mandtii", "ultimus", "ultimus", "arcticus", "arcticus", "arcticus",
    "arcticus", "arcticus", "arcticus", "islandicus", "grylle"
  ),
  POP = c("AK", "NU", "GR", "LB", "NF", "ST", "NS", "NB", "ME", "IC", "FI"),
  LON = c(-156, -82.5, -70.2, -61.7, -53.6, -69.7, -61.5, -66.8, -68.2, -22.9, 19.3),
  LAT = c(71.2, 65.9, 76.5, 56.6, 47.3, 47.8, 45.1, 44.6, 44.2, 65.4, 60.2),
  stringsAsFactors = FALSE
)

new_crs <- "+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.449 +units=m +no_defs"

col_coor <- col_coor %>% 
  st_as_sf(coords = c("LON", "LAT"), crs = 4326) %>%
  st_transform(crs = new_crs)

# world data
data("wrld_simpl", package = "maptools")
wrld_simpl <- st_as_sf(wrld_simpl) %>%
  st_crop(xmin = -180, xmax = 180, ymin = 35, ymax = 90) %>%
  st_transform(crs = new_crs)
#> although coordinates are longitude/latitude, st_intersection assumes that they are planar
#> Warning: attribute variables are assumed to be spatially constant throughout all
#> geometries

# plot
tm_shape(wrld_simpl) +
  tm_polygons() +
  tm_shape(col_coor) +
  tm_dots(col = "POP", size = 0.33) +
  tm_layout(legend.outside = TRUE, legend.text.size = 1.25, legend.title.size = 1.25)
#> Warning: The shape wrld_simpl is invalid. See sf::st_is_valid

Создано в 2020-02-14 пакетом Представить (v0.3.0)

Вы можете прочитать более подробную информацию о tmap здесь: https://geocompr.robinlovelace.net/adv-map.html

...