【发布时间】:2018-07-30 03:34:25
【问题描述】:
我正在尝试使用ggplot2 和新的(非常棒的)简单特征映射包geom_sf 将几个地理数据集绘制在一起。当我尝试强制 line 类型特征的图例显示为行。
这是我调用的生成下图的代码;一切都很好除了图例,其中 Line1 显示有一个框/填充。
ggplot() +
geom_sf(data=sct, aes(fill=as.factor(sct$tc2)), color = "gray82") +
scale_fill_manual(values=c("white","goldenrod1","dodgerblue"),
labels = c("Omitted", "Control", "Treated"),
name = "Legend") +
geom_sf(data=lines1925All, aes(color="A"), linetype="dashed") +
scale_color_manual(values = c("A" = "olivedrab"),
labels = c("Line1"),
name = "what line?") +
theme_minimal() +
coord_sf(xlim=mapRange2[c(1:2)], ylim=mapRange2[c(3:4)])
这是图表:
现在,如果我尝试使用show.legend(= TRUE 或= "line")将图例强制显示为一条线,则如下
geom_sf(data=lines1925All, aes(color="A"), linetype="dashed", show.legend = "line") +
我收到错误 Error: length(rows) == 1 is not TRUE。如果我单独绘制geom_sf 的任一实例,则不会出现错误,并且可以使用show.legend = "line" 使图例看起来正确。
注意:我没有包含一个最小的可重现示例,因为我无法通过易于共享的数据来复制它;见Add multiple legends to ggplot2 when using geom_sf。我已经尝试了几天才能找到答案,但没有运气。
【问题讨论】: