TLDR:如何更改下图中的默认行/标签间隔?
我正在尝试在 R 中制作地图图形。我的代码及其生成的图形如下所示。
我想更改图形,使纬度和经度的线条和标签出现在每个度数,而不是像现在这样,纬度每 0.5 度一次,经度每度一次。我该怎么做?
到目前为止,我最好的猜测是使用主题(axis.ticks)、主题(panel.grid)或它们的衍生物,但到目前为止还没有运气。
提前感谢您的帮助!
world <- ne_countries(scale = "large", returnclass = "sf")
north_america <- c("Canada", "United States of America")
na_map <- subset(world, name %in% north_america)
ggplot(data = na_map) +
geom_sf(fill = "lightgrey") +
xlim(-130, -122) +
ylim(45.7, 49.3)+
theme_dark()
您可以通过
breaks=
的scale_x/y_continuous
参数设置休息的次数和间隔。在那种情况下,我们还必须通过 limits=
参数设置限制,而不是使用便利函数 x/ylim()
:
library(ggplot2)
library(rnaturalearth)
world <- ne_countries(scale = "large", returnclass = "sf")
north_america <- c("Canada", "United States of America")
na_map <- subset(world, name %in% north_america)
ggplot(data = na_map) +
geom_sf(fill = "lightgrey") +
scale_x_continuous(
breaks = seq(-130, -122),
limits = c(-130, -122)
) +
scale_y_continuous(
breaks = seq(45, 49),
limits = c(45.7, 49.3)
) +
theme_dark()