我制作了这张地图,它几乎是完美的,除了插图周围有一个讨厌的白色蛀虫。我希望插图只有实际面板边框的黑线边框,而不是随之而来的白色背景。此外,我的panel.grid
元素没有显示在我绘制的陆地上方,并且希望它显示在陆地 mss 上方(在主地图中以浅灰色显示)。我panel.grid = element_line(color = "darkgray")
的主地图中有我的,但它仍然没有显示我想要的方式。我的比例尺和指北针也是如此。这是我的情节截图:
这是我用来生成地图的代码:
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") +
geom_sf(data = BCWA_land) +
xlim (-123.1, -121.4) +
ylim (47.0, 48.45) +
theme_bw()+
theme(panel.grid = element_line(color = "darkgray"),
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))
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(),
panel.background = element_blank()))
InsetMap
Figure1 <- MainMap +
annotation_custom(grob = InsetMap, xmin = -122.2, xmax = -121.3,
ymin = 47.75, ymax = 48.5) +
scalebar(x.min = -122.7, x.max = -122.5, y.min = 46.95, y.max = 47.1, location = "bottomright",
transform = TRUE, dist = 10, dist_unit = "km", st.size = 2, st.bottom = TRUE)
Figure1
在插图代码中,我设置了,panel.background = element_blank()
所以我不确定为什么我的插图周围仍然有白色背景/边框。
如果您需要我用来生成这些地图的数据,请告诉我。这是一个更大的文件,因此 SO 的字符限制限制了我可以放置的内容。即使我修剪数据,因为它们是多边形文件,单个数据行共享起来也很麻烦。
任何见解将不胜感激!