【问题标题】:Axis get reduced when using geom_sf and geom_point in R在 R 中使用 geom_sf 和 geom_point 时轴会减小
【发布时间】:2020-04-07 02:05:51
【问题描述】:

我使用的数据如下:

 mapa

 >Simple feature collection with 19 features and 11 fields
 >geometry type:  MULTIPOLYGON
 >dimension:      XY
 >bbox:           xmin: -1004502 ymin: 3132137 xmax: 1126932 ymax: 4859240
 >epsg (SRID):    25830
 >proj4string:    +proj=utm +zone=30 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m 
 >+no_defs
 >First 10 features:
 >     Codigo       Texto   Texto_Alt       CCAA  Muertes  Ciudad
 >1        01   Andalucía   Andalucía  Andalucía      491  Sevilla
 >2        02      Aragón      Aragón     Aragón      284  Zaragoza
 >3        03    Asturias    Asturias   Asturias       86  Oviedo
 >...
 >      Autonomía Superficie Habitantes Latitud Longitud                       geometry
 >1     Andalucía   14035.73     703206   37.38    -6.00 MULTIPOLYGON (((280486.8 39...
 >2        Aragón   17274.89     674317   41.66    -0.88 MULTIPOLYGON (((683851.1 47...
 >3      Asturias   10602.40     224005   43.36    -5.84 MULTIPOLYGON (((271018.9 48...
 >...

我很难理解为什么geom_point 中的轴会缩小并且没有在地图上绘制点。

 mapa %>% ggplot() +
      geom_sf(aes(fill = Superficie)) +
      geom_point(aes(x = Longitud, y = Latitud ,size = Muertes), 
                 color= "red", alpha = 1/2) 

这绘制了以下内容:

其实红点如下:

我是sf 的新手,但我知道这与数据代码中指定的bbox 项目有关。

我已经证明 coord_sf() 可以减少绘图窗口,但问题仍然存在。如果我将 LatitudLongitud 乘以 100000,我可以让点更接近,但点会扩大。

如何解决?

提前致谢。

【问题讨论】:

  • 您的地图和点不在同一个投影中。你可以阅读它here
  • @IanCampbell 它来自一长串连接,我可以在必要时指定它,但我认为它会搞砸帖子

标签: r maps sf


【解决方案1】:

好吧,正如我在第一条评论中所说,您的 sf 对象位于 utm 投影中,而您的点位于 lonlat 中。您可以使用函数st_transform 来完成工作。

mapa <- st_transform(mapa, crs = "+proj=longlat +datum=WGS84")

【讨论】:

  • 哎呀。当您发布答案时,我正在阅读您给我的链接。非常感谢!!!
  • 永远!!不要忘记查看该主题。
猜你喜欢
  • 2019-04-15
  • 1970-01-01
  • 2019-06-03
  • 1970-01-01
  • 1970-01-01
  • 2013-10-16
  • 2022-08-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多