0

I'm new to R so bear with me here. I have essentially recreated the 2016 electoral map with resulting data that I joined from various data frames.

I tried to introduce more arguments to my aes in geom_polygon, all of which seem to warp the map to a different appearance or introduce a new legend. Is there a way I can change the legend to not be of a scale, but of discrete information? I think the Blue column would be useful because it is boolean in nature with 1 representing that Clinton won that state and 0 indicating Trump won that state.

ggplot(data=states_w_votes) +
  geom_polygon(aes(x=long, y=lat, group=group, fill=Blue)) + 
  scale_fill_gradient(low="red", high="blue") +
  coord_quickmap()

enter image description here

florence-y
  • 751
  • 3
  • 8
  • 18

1 Answers1

0

It's hard to test without proper reproducible data But most likely you'll need to change your numeric values to factors and then use a discrete fill scale. Perhaps

ggplot(data=states_w_votes) +
  geom_polygon(aes(x=long, y=lat, group=group, fill=factor(Blue))) + 
  scale_fill_manual(values=c("red","blue"), breaks=c(0,1)) +
  coord_quickmap()

You could also pass the color directly, like

ggplot(data=states_w_votes) +
  geom_polygon(aes(x=long, y=lat, group=group, fill=ifelse(Blue, "blue","red"))) + 
  scale_fill_identity() +
  coord_quickmap()
MrFlick
  • 195,160
  • 17
  • 277
  • 295