R语言 如何制作南极洲1/2的Map

63lcw9qa  于 2023-05-26  发布在  其他
关注(0)|答案(2)|浏览(155)

我想画一张半个南极洲的Map。我需要绘制西半部(罗斯海的一半),从120ºE到60ºW。
我使用了similar question的参考代码来制作下图:

我已经包含了我用来制作下图的代码。要在120ºE到60ºW的线上将此Map切成两半,我尝试过

coord_map("ortho", orientation = c(-90, 210, 0), xlim = (120,-60)) +

其仅切除纬度+经度线的一些区段;

scale_x_continuous(limits = c(120, -60), breaks = NULL) +

这是接近,并作出了这个数字(这是错误的1/2):

以及这些代码的很多很多次迭代(是的,我试过交换到c(-60,120),这使得一个空白的Map上有lat +长的线条)。我可以裁剪图像,我可能会诉诸,但我想找到“正确”的解决方案。以下是我的完整参考代码:

library("cowplot")
library("googleway")
library("ggplot2")
library("ggrepel")
library("ggspatial")
library("sf")
library("rnaturalearth")
library("rnaturalearthdata")
library("raster")
library("mapproj")
library("rgdal")

# Defines the x axes required
x_lines <- seq(-120,180, by = 60)
wm <- map_data("world")

# Whole Map
ggplot() +
  geom_polygon(data = wm, aes(x = long, y = lat, group = group), fill = "grey", colour = "black", alpha = 0.8) +
  
  # Convert to polar coordinates
  coord_map("ortho", orientation = c(-90, 210, 0)) +
  scale_y_continuous(limits=c(-90,-60), breaks = seq(-45, -90, by = -10), labels = NULL) +
  
  # Removes Axes and labels
  scale_x_continuous(breaks = NULL) +
  xlab("") + 
  ylab("") +
  
  # Adds labels
  geom_text(aes(x = 90, y = seq(-55, -85, by = -10), hjust = -0.2, label = paste0(seq(55, 85, by = 10), "°S"))) +
  geom_text(aes(x = x_lines, y = -63, label = c("120°W", "60°W", "0°", "60°E", "120°E", "180°W"))) +
  
  # Adds axes
  geom_hline(aes(yintercept = -60), size = 1)  +
  geom_segment(aes(y = -60, yend = -90, x = x_lines, xend = x_lines), linetype = "dashed") +

 # Change theme to remove axes and ticks
  theme(panel.background = element_blank(),
        panel.grid.major = element_line(size = 0.25, linetype = 'dashed',colour = "black"),
        axis.ticks=element_blank())
vhipe2zx

vhipe2zx1#

也许这就是你要找的。要获取Map的上半部分,我使用xlim = c(-60, -240)。另外,我已经或已经将x和y尺度的扩展设置为零。此外,我稍微移动了hline和线段的位置,以防止geom_hline在达到极限时被切断。最后,我添加了一个geom_label,以在限制内添加60°W120°E的外部标签。

library("ggplot2")

# Defines the x axes required
x_lines <- seq(-120, 180, by = 60)
wm <- map_data("world")

# Whole Map
ggplot() +
  geom_polygon(
    data = wm, aes(x = long, y = lat, group = group),
    fill = "grey", colour = "black", alpha = 0.8
  ) +
  geom_text(aes(
    x = -90, y = seq(-65, -85, by = -10), hjust = -0.2,
    label = paste0(seq(65, 85, by = 10), "°S")
  )) +
  geom_text(aes(
    x = x_lines[-c(2, 5)], y = -63,
    label = c("120°W", "0°", "60°E", "180°W")
  )) +
  geom_label(
    aes(
      x = x_lines[c(2, 5)], y = -63,
      label = c("60°W", "120°E")
    ),
    vjust = 0, fill = NA, label.size = 0
  ) +
  geom_hline(aes(yintercept = -60.5), linewidth = 1) +
  geom_segment(
    aes(y = -60.5, yend = -90, x = x_lines, xend = x_lines),
    linetype = "dashed"
  ) +
  scale_y_continuous(
    limits = c(-90, -60), breaks = seq(-45, -90, by = -10),
    labels = NULL, expand = c(0, 0)
  ) +
  scale_x_continuous(breaks = NULL, expand = c(0, 0)) +
  theme(
    panel.background = element_blank(),
    panel.grid.major = element_line(
      linewidth = 0.25,
      linetype = "dashed", colour = "black"
    ),
    axis.ticks = element_blank()
  ) +
  coord_map("ortho", orientation = c(-90, 210, 0), xlim = c(-60, -240)) +
  labs(x = NULL, y = NULL)

igsr9ssn

igsr9ssn2#

使用{sf}的另一种方法:

library(sf)
library(ggplot2)
library(rnaturalearth)

antarctica <- ne_countries(continent = 'Antarctica', scale = 'large') |>
  st_as_sf() |> ## convert to class "sf" for use with {sf}
  st_geometry() |>## keep geometry, not attributes
  st_make_valid()

cropping_region <- 
  list(matrix(c(60, 120, 120, 60, 60,
                -90, -90, -63, -63, -90), , 2)
       ) |> st_polygon()

antarctica_cropped <- antarctica |> 
  st_crop(cropping_region) |>
  st_make_valid() |>
  st_transform(32761) ## reproject to EPSG 32761 for south polar region

bbox <- antarctica_cropped |> st_bbox()

antarctica_cropped |> 
  ggplot() +
  geom_sf(mapping = aes()) +
  coord_sf(xlim = c(bbox[1], bbox[3]),
           ylim = c(bbox[2], bbox[3])
)

相关问题