【问题标题】:How to draw a round map projection in R with a rectangle around specific area?如何在 R 中用特定区域周围的矩形绘制圆形地图投影?
【发布时间】:2023-01-30 21:03:57
【问题描述】:

我需要在 R 中制作一张与这张地图类似的地图,但在乌拉圭绘制了一个矩形: enter image description here

我正在尝试使用 ggplot,但地球没有边框,我找不到指示坐标的方法来绘制我感兴趣的矩形。这是我在 web 之后获得的:

enter image description here

任何帮助表示赞赏!谢谢

【问题讨论】:

    标签: r ggplot2 maps map-projections


    【解决方案1】:

    您可以使用 ggplot2 库在 R 中绘制圆形地图投影,并在特定区域周围绘制一个矩形。这是一个基本示例:

    library(ggplot2)
    
    # Load data
    data(world)
    
    # Create a round projection
    p <- ggplot() + 
      geom_sf(data = world, fill = "gray80") + 
      coord_sf(crs = "+proj=longlat +datum=WGS84") + 
      theme_void()
    
    # Define the rectangle coordinates
    rect_coords <- data.frame(
      xmin = c(-120, -120),
      xmax = c(-60, -60),
      ymin = c(30, 50),
      ymax = c(40, 70)
    )
    
    # Add rectangle to plot
    p + geom_rect(
      data = rect_coords,
      aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax),
      fill = "red",
      alpha = 0.5
    )
    
    

    【讨论】:

    • 我需要这样做,但随着地球的圆形投影
    猜你喜欢
    • 2022-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-03
    • 2014-07-06
    相关资源
    最近更新 更多