세계지도를 그릴 때 ggplot2
에 문제가 있습니다. 전체 배경을 같은 색상으로 채 웁니다. 하도록하기 위해ggplot2 (및 sf)의 세계지도 용 전체 지구 다각형
#install.packages("devtools")
#devtools::install_github("tidyverse/ggplot2")
#devtools::install_github("edzer/sfr")
library(ggplot2)
library(sf)
library(rnaturalearth)
library(dplyr)
theme_map <- function(...) {
theme_minimal() +
theme(
text = element_text(family = "Ubuntu Regular", color = "#22211d"),
axis.line = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.minor = element_line(color = "#ebebe5", size = 0.2),
panel.grid.major = element_line(color = "#ebebe5", size = 0.2),
plot.background = element_rect(fill = "#f5f5f2", color = NA),
panel.background = element_rect(fill = "#f5f5f2", color = NA),
legend.background = element_rect(fill = "#f5f5f2", color = NA),
panel.border = element_blank(),
...
)
}
crs <- "+proj=laea +lat_0=52 +lon_0=10 +x_0=00 +y_0=3210000 +datum=WGS84 +units=m +no_defs"
ctrys50m <- ne_countries(scale = 50, type = "countries", returnclass = "sf") %>%
select(iso_a3, iso_n3, admin)
ggplot() +
geom_sf(data = ctrys50m, alpha = 0.15, fill="grey") +
coord_map() +
coord_sf(crs = crs) +
theme_map()
: 세계는, 아래의 다음 코드에 의해 생성 된 스냅 샷 참조 (이 가장자리 sf
ABD ggplot2
버전을 bleading 사용하지만 문제는 제네릭을, 아래에 언급 된 블로그 게시물을 참조) 멋지게 지구의 등고선을 그릴 수있다.,923,210 GeoJSON type
, {type: "Sphere"}
특별한 행동 here에서 볼 수 this thread 참조 추가되었습니다
유일한 트릭 내가 찾은 : 그것은 다음과 같은 스냅 샷의 외부 전체 지구 검은 색 테두리가 R
/ggplot2
은 Matt Strimas-Mackey가 블로그 항목 Mapping the Longest Commericial Flights in R에 게시했으며 Bounding box and graticules 섹션과 make_bbox
및 project_recenter
기능을 참조하십시오.
이
코드의 꽤 많이하고 좀sf
또는
geom_sf
코드가 청소기/간단한 코드를 만들 것인지 궁금 해서요, 그래서 시도 : 내가 얻을 것은 단지 여분이다
# whole world WSG84 bounding box
sphere <- ne_download(category = "physical", type = "wgs84_bounding_box", returnclass = "sf")
sphere_laea <- st_transform(sphere, crs)
ggplot() +
geom_sf(data = sphere, fill = "#D8F4FF") +
coord_sf(crs = crs) +
geom_sf(data = ctrys50m, alpha = 0.15, fill="grey") +
coord_map() +
coord_sf(crs = crs) +
theme_map()
" 반대로 자오선 "(북극에서 선을주의하십시오 ...) 그리고 no 대양#D8F4FF
... 로 채웠다 그리고 다각형은 바닥에 확실히 불규칙하다 (D3.js 지도자는 약간 똑똑한 adaptive resampling 정확도를 증가시켰다 투영 된 선의 ...)
ggplot2 세계지도에서 전체 폴리곤을 얻으려는 시도에있어 잘못된 점에 대한 아이디어가 있습니까? (지금까지 읽어 주셔서 감사합니다)
이 환상적인 제안이다 : 다음 코드는 매우 좋은 결과 (후 이미지 참조) 제공합니다. 더 좋은 다각형을 가지려면'ne_countries (scale = 10, ...) '을 사용 하겠지만, 그렇지 않으면 실용적인 해결책입니다. 감사! – espinielli
다음과 같이 '구형'이라는 정의를 사용하여 눈에 잘 띄는 모서리가없는 매우 좋은 결과를 얻었습니다. 'sphere'- st_graticule (ndiscr = 10000, margin = 10e-6) %> % st_transform (crs = crs) %> % st_convex_hull() %> 요약 (geometry = st_union (geometry))' – espinielli