使用 geom_sf() 绘制世界地图时缺少轴刻度和标签
Missing axis ticks and labels when plotting world map with geom_sf()
绘制基本世界地图时,我没有在坐标轴上显示纬度和经度。我在 cran 上做了 geom_sf()
提供的示例,它确实显示了经纬度。
下面是我的代码。
library("ggplot2")
library("sf")
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
library("rnaturalearth")
library("rnaturalearthdata")
world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
#> [1] "sf" "data.frame"
ggplot(data = world) +
geom_sf() +
coord_sf()
这是在坐标轴上生成经纬度的示例代码。
nc <- st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source `/Library/Frameworks/R.framework/Versions/3.6/Resources/library/sf/shape/nc.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> geometry type: MULTIPOLYGON
#> dimension: XY
#> bbox: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> epsg (SRID): 4267
#> proj4string: +proj=longlat +datum=NAD27 +no_defs
ggplot(nc) + geom_sf()
coord_sf()
仅当格线实际到达轴时才绘制轴刻度。在您的世界地图中,绘图面板扩展到地球的大小之外(您可以看到经纬线在绘图面板的边缘之前结束),因此没有绘制轴刻度。
解决此问题的一种方法是关闭扩展。
library("ggplot2")
library("sf")
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
library("rnaturalearth")
library("rnaturalearthdata")
world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
#> [1] "sf" "data.frame"
ggplot(data = world) +
geom_sf() +
coord_sf(expand = FALSE)
由 reprex package (v0.3.0)
于 2019-11-02 创建
绘制基本世界地图时,我没有在坐标轴上显示纬度和经度。我在 cran 上做了 geom_sf()
提供的示例,它确实显示了经纬度。
下面是我的代码。
library("ggplot2")
library("sf")
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
library("rnaturalearth")
library("rnaturalearthdata")
world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
#> [1] "sf" "data.frame"
ggplot(data = world) +
geom_sf() +
coord_sf()
这是在坐标轴上生成经纬度的示例代码。
nc <- st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source `/Library/Frameworks/R.framework/Versions/3.6/Resources/library/sf/shape/nc.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> geometry type: MULTIPOLYGON
#> dimension: XY
#> bbox: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> epsg (SRID): 4267
#> proj4string: +proj=longlat +datum=NAD27 +no_defs
ggplot(nc) + geom_sf()
coord_sf()
仅当格线实际到达轴时才绘制轴刻度。在您的世界地图中,绘图面板扩展到地球的大小之外(您可以看到经纬线在绘图面板的边缘之前结束),因此没有绘制轴刻度。
解决此问题的一种方法是关闭扩展。
library("ggplot2")
library("sf")
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
library("rnaturalearth")
library("rnaturalearthdata")
world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
#> [1] "sf" "data.frame"
ggplot(data = world) +
geom_sf() +
coord_sf(expand = FALSE)
由 reprex package (v0.3.0)
于 2019-11-02 创建