I am trying to graph several geographic datasets together using the ggplot2
and the new (and awesome) simple features mapping packages geom_sf
. I'm flummoxed by the legends and an error code Error: length(rows) == 1 is not TRUE
(which seems to belong to ddply
) that results when I try to force the legend of a line type feature to show up as a line.
Here is code I call that generates the graph below; everything is fine except the legend, which has Line1 displayed with a box/fill.
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)])
This is the graph:
Now, if I try to force the legend to the look like a line using show.legend
(either = TRUE
or = "line"
), in the following
geom_sf(data=lines1925All, aes(color="A"), linetype="dashed", show.legend = "line") +
I get the error Error: length(rows) == 1 is not TRUE
. If I graph either instance of geom_sf
alone, I get no error, and can make the legend look correct by using show.legend = "line"
.
Note: I have not included a minimal reproducible example because I have been unable to replicate this with easy to share data; see Add multiple legends to ggplot2 when using geom_sf. I have tried for a few days to find an answer, with no luck.