我在为地图定稿时遇到一些问题。我认为我对解决方案很热情,但是还没有弄清楚。我真的很感谢解决方案方面的任何帮助,以便我最终可以继续前进!
1)比例尺不会填充在MainMap
代码和后续的Figure1
图中。如果我注释掉“ BCWA_land”地图图层,则在MainMap
代码中对此进行“补救”。但是,当我保留“ BCWA_land”地图图层时,它将消除比例尺并产生此错误:
Warning message: Removed 3 rows containing missing values (geom_text).
这是代码:
MainMap <- ggplot(QOI) +
geom_sf(aes(fill = quadID)) +
scale_fill_manual(values = c("#6b8c42",
"#70b2ae",
"#d65a31")) +
labs(fill = "Quadrants of Interest",
caption = "Figure 1: Map depicting the quadrants in the WSDOT project area as well as other quadrants of interest in the Puget Sound area.")+
ggtitle("WSDOT Project Area and Quadrants of Interest") +
scalebar(x.min = -123, x.max = -122.8, y.min = 47, y.max = 47.1, location = "bottomleft",
transform = TRUE, dist = 10, dist_unit = "km", st.size = 3, st.bottom = TRUE, st.dist = 0.1) +
north(data = QOI, location = "topleft", scale = 0.1, symbol = 12, x.min = -123, y.min = 48.3, x.max = -122.7, y.max = 48.4) +
theme_bw()+
theme(panel.grid= element_line(color = "gray50"),
panel.background = element_blank(),
panel.ontop = TRUE,
legend.text = element_text(size = 11, margin = margin(l = 3), hjust = 0),
legend.position = c(0.95, 0.1),
legend.justification = c(0.85, 0.1),
legend.background = element_rect(colour = "#3c4245", fill = "#f4f4f3"),
axis.title = element_blank(),
plot.title = element_text(face = "bold", colour = "#3c4245", hjust = 0.5, margin = margin(b=10, unit = "pt")),
plot.caption = element_text(face = "italic", colour = "#3c4245", margin = margin(t = 7), hjust = 0, vjust = 0.5)) +
geom_sf(data = BCWA_land) + #this is what I've tried to comment out to determine the scale bar problem
xlim (-123.1, -121.4) +
ylim (47.0, 48.45)
MainMap
InsetRect <- data.frame(xmin=-123.2, xmax=-122.1, ymin=47.02, ymax=48.45)
InsetMap <- ggplotGrob( ggplot( quads) +
geom_sf(aes(fill = "")) +
scale_fill_manual(values = c("#eefbfb"))+
geom_sf(data = BCWA_land) +
scale_x_continuous(expand = c(0,0), limits = c(-124.5, -122.0)) +
scale_y_continuous(expand = c(0,0), limits = c(47.0, 49.5)) +
geom_rect(data = InsetRect,aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax),
color="#3c4245",
size=1.25,
fill=NA,
inherit.aes = FALSE) +
theme_bw()+
theme(legend.position = "none",
panel.grid = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
plot.margin = margin(0,0,0,0)))
InsetMap
Figure1 <- MainMap +
annotation_custom(grob = InsetMap, xmin = -122.2, xmax = -121.3,
ymin = 47.75, ymax = 48.5)
Figure1
您可以看到我的北箭头没有收到这个问题或错误,所以我不确定比例尺是怎么回事!
InsetMap
上,并希望InsetMap
可以覆盖在[ MainMap
,没有网格线,因为我在element_blank()
代码中将这些参数设置为InsetMap
。这里是我的情节的图片。如果您需要有关此数据,请告诉我。由于这些文件是shapefile,因此数据笨拙且不利于SO的字符数限制。]
[如果有人对解决方案有任何见解,我将非常感谢!!感谢您的宝贵时间!
问题是
xlim (-123.1, -121.4) +
ylim (47.0, 48.45)
我打过电话。相反,我使用了coord_sf(xlim = c(min, max), ylim = c(min, max))
。我认为这对以后可能会担任我职位的人会有帮助!
本质上,仅使用x / y lim调用来设置图的限制之间的区别在于,它会截断数据集中可用的数据,而coord_sf调用只是将图“聚焦”在该范围内(如果您愿意而不更改数据集中可用的数据。