0

我在为报告定稿时遇到了一些问题。我想我对解决方案很热情,但还没有完全弄清楚。我非常感谢任何有关解决方案的帮助,以便我最终可以继续前进!

1) 比例尺不会填充在MainMap代码和后续 Figure1图中。MainMap如果我注释掉“BCWA_land”地图图层,这将在代码中“修复”。但是,当我保留“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

如您所见,我的指北针没有遇到此问题或错误,因此我不确定比例尺发生了什么!

  1. 这个问题可能有点太强迫症了,但是我真的不希望网格线出现在 上InsetMap,并且希望InsetMap不会覆盖在 上,因为我在代码中MainMap设置了这些参数。element_blank()InsetMap

这是我的情节的图像。如果你想要这方面的数据,请告诉我。因为这些是 shapefile,所以数据很笨重,而且不利于 SO 的帖子字符限制......

在此处输入图像描述

如果有人对解决方案有任何见解,我将不胜感激!谢谢你的时间!

4

1 回答 1

0

问题是

 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 调用只是将图表“聚焦”在该范围上,如果你愿意的话而不改变您在数据集中可用的数据。

于 2020-05-26T22:43:48.687 回答