I'm mapping and I can't make the legend become unified.
This is my code:
ggplot() +
geom_sf(data = all_boundaries$osm_multipolygons,
inherit.aes = TRUE,
color = "lightgrey",
size = 0.7,
alpha = 0.8) +
geom_sf(data = all_boundaries$osm_lines,
inherit.aes = TRUE,
linetype = "dotted",
color = "#D55E00",
size = 0.7,
alpha = 0.8) +
geom_sf(data = coast$osm_lines,
inherit.aes = TRUE,
color = "#56B4E9",
size = 12) +
coord_sf(xlim = c(-113.517109, -117.823506),
ylim = c(30.742140, 33.961826),
expand = FALSE) +
theme_bw() +
labs(x = NULL, y = NULL) +
geom_path(data = ros, aes(x = long, y = lat,linetype = "Mexican ducts"), alpha = 0.5) +
geom_point( aes(x = -116.8476211, y = 31.9885162, color = "LNG terminal",shape="LNG terminal"), fill = "#CC79A7", size = 2) +
geom_line(data = amp, aes(x = long, y = lat), alpha = 0.5) +
geom_path(data = nbaja, aes(x = lat, y = long,linetype = "US ducts"), alpha = 0.5) +
geom_path(data = sand, aes(x = long, y = lat), linetype = "longdash", alpha = 0.5) +
geom_path(data = soca, aes(x = long, y = lat), linetype = "longdash", alpha = 0.5) +
geom_point( aes(x = -115.428521, y = 32.669708), shape = 23, fill = "#000000") +
geom_point( aes(x = -116.898, y = 32.5534), shape = 23, fill = "#000000") +
geom_point( aes(x = -114.773898, y = 32.715056, shape = "Interconnectors"), fill = "#000000") +
geom_point(data = plants, aes(x = long, y = lat, color = "Power plants",shape = "Power plants"), fill = "#D55E00", alpha = 0.5, size = 1.5)+
scale_color_manual(values = c("Power plants" = "#D55E00", "LNG terminal" = "#CC79A7", "Interconnectors" = "#000000", "Mexican ducts" = "#999999", "US ducts" = "#999999"),
labels = c("Power plants", "LNG terminal", "Interconnectors", "Mexican ducts", "US ducts"),
guide = guide_legend(override.aes = list(shape = NA, linetype = NA))) +
scale_shape_manual(values = c("Power plants" = 21, "LNG terminal" = 15, "Interconnectors" = 23, "Mexican ducts" = NA, "US ducts" = NA),
labels = c("Power plants", "LNG terminal", "Interconnectors", "Mexican ducts", "US ducts"),
guide = guide_legend(override.aes = list(color = c("#D55E00", "#CC79A7", "#000000", "#999999", "#999999"),
linetype = c(NA, NA, NA, "solid", "longdash")))) +
guides(color = guide_legend(order = 1, title = "Legend"),
shape = guide_legend(order = 2))
I get a legend where shape, colors, and lines are correctly identified but I can make it transform into just one legend. I want:
"LNG terminal"
color = "#CC79A7"
and shape=15
;
"Power plants"
color="#D55E00"
and shape=21
;
"Interconnectors"
shape=23
;
"Mexican ducts"
color="#999999"
and linetype="solid"
;
and US ducts
color="#999999"
and linetype="longdash"
in a single legend.