I am trying to create a legend denoting how the plot is color coded. However, this legend is not showing.
Here is what the output currently is:
Does this have something to do with the current plot already taking up the entire space?
Here is my code below to create the plot (and attempt to add a legend):
cols <- c("50 miles"="#B10026","100 miles"="#FC4E2A","150 miles"="#FEB24C", "200 miles"="#FFEDA0")
hurricane_plot <- ggplot(data = US_subset_counties) +
geom_polygon(mapping = aes(x = long, y = lat, group = group), size = 0.2, color="gray", fill=NA) +
geom_polygon(data=counties_200, aes(x = long, y = lat, group = group), size = 0.2, fill="#FFEDA0") +
geom_polygon(data=counties_150, aes(x = long, y = lat, group = group), size = 0.2, fill="#FEB24C") +
geom_polygon(data=counties_100, aes(x = long, y = lat, group = group), size = 0.2, fill="#FC4E2A") +
geom_polygon(data=counties_50, aes(x = long, y = lat, group = group), size = 0.2, fill="#B10026") +
geom_polygon(data=US_subset_states, aes(x = long, y = lat, group = group), size = 0.2, color = "black", fill=NA) +
theme_bw() +
theme(panel.background = element_blank()) +
scale_colour_manual(name="Distance From Radius",values=cols)
hurricane_plot
Thanks in advance!
EDIT:
After @Ben's comment, I tried putting fill inside the aes to no avail. However, when I changed fill to col and used guides, this is the result I get:
How would I change the colors of the boxes and labels to the cols vector above, and is there a way to remove the border colors on my plot?
This is my updated code:
hurricane_plot <- ggplot(data = US_subset_counties) +
geom_polygon(mapping = aes(x = long, y = lat, group = group), size = 0.2, color="gray", fill=NA) +
geom_polygon(data=counties_200, aes(x = long, y = lat, group = group, color="#FFEDA0"), size = 0.2, fill="#FFEDA0") +
geom_polygon(data=counties_150, aes(x = long, y = lat, group = group, color="#FEB24C"), size = 0.2, fill="#FEB24C") +
geom_polygon(data=counties_100, aes(x = long, y = lat, group = group, color="#FC4E2A"), size = 0.2, fill="#FC4E2A") +
geom_polygon(data=counties_50, aes(x = long, y = lat, group = group, color="#B10026"), size = 0.2, fill="#B10026") +
geom_polygon(data=US_subset_states, aes(x = long, y = lat, group = group), size = 0.2, color = "black", fill=NA) +
theme_bw() + theme(panel.background = element_blank()) +
guides(color=guide_legend("Distance From Radius"))
fill =
in eachgeom_polygon
into theaes
and usingscale_fill_manual
? – BenUS_subset_counties
,counties_200
,counties_150
, etc. and will try to provide an answer. Hope this will help. – Ben