我在用sf
和ggplot2
做 map .是否可以调整X轴,以便我可以:
1-精确到我想要的休息次数(在本例中为4)
2-使第一个和最后一个标签从轴的起点和结尾处开始(即与绘图边框没有间隙)
library(ggplot2)
library(sf)
#> Linking to GEOS 3.11.1, GDAL 3.6.2, PROJ 9.1.1; sf_use_s2() is TRUE
library(patchwork)
poly <- rnaturalearth::ne_countries(
country = c("Canada", "Belgium"),
scale = "medium",
returnclass = "sf"
)
make_plot <- function(poly) {
bbox <- st_bbox(poly)
xmin <- bbox[1]
xmax <- bbox[3]
xbreaks <- pretty(seq(xmin, xmax, length.out = 4), n = 4)
ggplot() +
geom_sf(data = poly) +
scale_x_continuous(breaks = xbreaks) +
coord_sf(xlim = c(xmin, xmax), expand = FALSE)
}
p1 <- make_plot(poly[poly$name_en == "Canada", ])
p2 <- make_plot(poly[poly$name_en == "Belgium", ])
p1 + p2
创建于2023-04-14年第reprex v2.0.2页