0

I'm trying to create a more aesthetically pleasing graph. For some reason I am producing 2 legends at the top of my chart. I would like only the one on the right to remain, but I cannot figure out what I am doing wrong. Here is my code and graph.

plt <- ggplot(ac_total_melt, aes(Date, Value, fill = Action)) + 

  geom_line(
    aes(color = Action),
    size = .9
  )+
  geom_point(aes(colour = Action))+
  ylab("")+
 scale_color_manual(values=c('Dark Green','Dark red'), labels = c("Number Closed", "Number Opened"))+
  geom_text_repel(
    aes(color = Action, label = Value),
    show.legend = FALSE,
    family = "Lato",
    fontface = "plain",
    size = 4,
    direction = "y"
  )  + 
  theme(legend.position="top")+ 
  guides(color = guide_legend (override.aes = list(linetype = 0, size=5)))

plt

Data: Data

Graph with 2 legends

  • 1
    It seems like one legend is coming from the color, and the other from the fill, which you don't seem to be using anyway. It's hard to do more than guess without a [reproducible example](https://stackoverflow.com/q/5963269/5325862) – camille Aug 18 '21 at 17:28
  • How about removing `fill = Action`? I don't think it is used any of the geoms (point, text, line). – Kota Mori Aug 18 '21 at 17:46

2 Answers2

0

Looks like I needed to add show_guide = F to geom_point

0

The issue is that you re-labeled the fill scale, but not the color scale, so ggplot isn't able to merge them:

plt <- ggplot(ac_total_melt, aes(Date, Value, fill = Action, color = Action)) + 
  geom_line(size = .9) +
  geom_point() +
  ylab("") +
  scale_color_manual(
    values=c('blue', 'green'), 
    labels = c("Number Closed", "Number Opened"),
    aesthetics = c("color", "fill") # apply this scale to both color and fill
  ) +
  geom_text_repel(
    aes(label = Value),
    show.legend = FALSE,
    family = "Lato",
    fontface = "plain",
    size = 4,
    direction = "y"
  )  + 
  theme(legend.position = "top")+ 
  guides(color = guide_legend(override.aes = list(linetype = 0, size = 5)))

plt
Brenton M. Wiernik
  • 1,006
  • 4
  • 8