챗GPT 지도제작을 위해서…..

지도제작을 위한 다양한 정보를 모아 공개하고 있습니다.

저자
소속

1 참고 웹사이트

2 원천 지도

3 세계지도

코드
library(tidyverse)
library(sf)

# download.file(url = "https://gisco-services.ec.europa.eu/distribution/v2/countries/geojson/CNTR_RG_01M_2016_4326.geojson", destfile = "data/world.geojson", mode = "w")
# 
# world_sf <- giscoR::gisco_get_countries(
#   epsg = "4326",
#   region = "Asia",
#   resolution = "1",
#   cache = TRUE, 
#   update_cache = TRUE
# )

world_sf <- sf::st_read("data/world.geojson")
#> Reading layer `world' from data source `D:\tcs\map_challenge\data\world.geojson' using driver `GeoJSON'
#> Simple feature collection with 257 features and 6 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -180 ymin: -89.9 xmax: 180 ymax: 83.66498
#> Geodetic CRS:  WGS 84

plot(st_geometry(world_sf))

코드
# 필요한 라이브러리를 불러옵니다.
library(ggplot2)
library(maps)

# 월드맵 데이터를 불러옵니다.
world_map <- map_data("world")

# ggplot2를 사용해 지도를 그립니다.
ggplot() +
  geom_polygon(data = world_map, aes(x = long, y = lat, group = group), fill = "white", color = "black") +
  coord_cartesian(xlim = c(-180, 180)) +
  theme_void()

코드
library(rnaturalearth)

# Get the world map data
world <- ne_countries(scale = "medium", returnclass = "sf")

# Shift the map to center on the Pacific Ocean
world_trans <- st_transform(st_wrap_dateline(world, options = c("WRAPDATELINE=YES", "DATELINEOFFSET=-180")), crs = "+proj=robin")

# Plot the world map
ggplot(data = world_trans) +
  geom_sf() +
  theme_minimal()

코드
asia_sf <- giscoR::gisco_get_countries(
  epsg = "4326",
  region = "Asia",
  resolution = "60",
  cache = TRUE,
  update_cache = TRUE
)

plot(st_geometry(asia_sf))

코드
library(tidyverse)
library(sf)
library(giscoR)

korea <- giscoR::gisco_get_countries(
    resolution = "1",
    country = "KOR"
) |>
    sf::st_transform("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")

plot(st_geometry(korea))

코드
library(maps)

plot.map<- function(database,center,...){
    Obj <- map(database,...,plot=F)
    coord <- cbind(Obj[[1]],Obj[[2]])

    # split up the coordinates
    id <- rle(!is.na(coord[,1]))
    id <- matrix(c(1,cumsum(id$lengths)),ncol=2,byrow=T)
    polygons <- apply(id,1,function(i){coord[i[1]:i[2],]})

    # split up polygons that differ too much
    polygons <- lapply(polygons,function(x){
        x[,1] <- x[,1] + center
        x[,1] <- ifelse(x[,1]>180,x[,1]-360,x[,1])
        if(sum(diff(x[,1])>300,na.rm=T) >0){
          id <- x[,1] < 0
          x <- rbind(x[id,],c(NA,NA),x[!id,])
       }
       x
    })
    # reconstruct the object
    polygons <- do.call(rbind,polygons)
    Obj[[1]] <- polygons[,1]
    Obj[[2]] <- polygons[,2]

    map(Obj,...)
}

plot.map("world", center=210, col="white",bg="gray",
         fill=TRUE, ylim=c(-60,90),mar=c(0,0,0,0))