在 R 中使用 geom_sf 和 geom_point 时轴变小
Axis get reduced when using geom_sf and geom_point in R
我使用的数据如下:
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()
证明可以减少情节 window 但问题仍然存在。如果我将 Latitud
和 Longitud
乘以 100000,我可以使点更接近,但点会扩大。
如何修复?
提前致谢。
好吧,正如我在第一条评论中所说,您的 sf 对象在 utm 投影中,而您的点在 lonlat 中。您可以使用函数 st_transform
来完成这项工作。
mapa <- st_transform(mapa, crs = "+proj=longlat +datum=WGS84")
我使用的数据如下:
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()
证明可以减少情节 window 但问题仍然存在。如果我将 Latitud
和 Longitud
乘以 100000,我可以使点更接近,但点会扩大。
如何修复?
提前致谢。
好吧,正如我在第一条评论中所说,您的 sf 对象在 utm 投影中,而您的点在 lonlat 中。您可以使用函数 st_transform
来完成这项工作。
mapa <- st_transform(mapa, crs = "+proj=longlat +datum=WGS84")