【发布时间】:2020-06-17 14:13:31
【问题描述】:
我正在尝试使用使用 ggmap (get_stamenmap) 拉入的基本地图创建地图,其中一些 shapefile 放在顶部 (geom_sf)。我想更改轴标签!为什么这么难!
当我只绘制我的底图时,我得到标有纬度/经度和无字符的轴 - 即 -19
当我使用
geom_sf添加 shapefile 时,我得到标有纬度/经度和字符的轴 - 即 19°S当我尝试使用
scale_x_discrete和sf_coord(expand = F)更改轴标签时,我可以得到我想要的当我根据需要添加带有标签文本的
scale_y_discrete时,我不断收到此错误:
错误:沿 y 方向的断点和标签长度不同
这里发生了什么?我缺少的 y 轴上是否有不可见的中断?
这行得通:
ggmap(SA) +
geom_sf(data = traj_outSF, alpha = 0.4, inherit.aes = F) +
coord_sf(expand = FALSE) +
xlab(expression(paste("Longitude (", degree,"E)"))) +
ylab(expression(paste("Latitude (", degree,"S)"))) +
scale_x_discrete(breaks = c(33.5, 34, 34.5, 35, 35.5),
labels = c("33.5", "34", "34.5", "35", "35.5"))
然后给我这个:
我添加scale_y_discrete 后立即收到错误消息
ggmap(SA) +
geom_sf(data = traj_outSF, alpha = 0.4, inherit.aes = F) +
coord_sf(expand = FALSE) +
xlab(expression(paste("Longitude (", degree,"E)"))) +
ylab(expression(paste("Latitude (", degree,"S)"))) +
scale_x_discrete(breaks = c(33.5, 34, 34.5, 35, 35.5),
labels = c("33.5", "34", "34.5", "35", "35.5"))
scale_y_discrete(breaks = c(20, 19.5, 19, 18.5, 18,17.5),
labels = c("20","19.5","19","18.5","18","17.5"))
这是一个代表:
g = st_sfc(st_point(c(34,-19)))
st_crs(g) <- 4326
SA <- get_stamenmap(bbox = c(33.18, -20.3, 35.8, -17.3),
maptype = "toner-lite",
zoom = 11)
ggmap(SA) +
geom_sf(data = g) +
coord_sf(expand = F) +
scale_x_discrete(breaks = c(33.5, 34, 34.5, 35, 35.5),
labels = c("33.5", "34", "34.5", "35", "35.5")) +
scale_y_discrete(breaks = c(20, 19.5, 19, 18.5, 18,17.5),
labels = c("20","19.5","19","18.5","18","17.5"))
谢谢!
【问题讨论】:
-
我认为这就是你所追求的
scale_x_continuous,而不是scale_x_discretestackoverflow.com/questions/33302424/…