Home > Mobile >  Legend Titles with two Lines
Legend Titles with two Lines

Time:12-23

I have a chart with two lines, based on different databases. The first line has colours, and the second line doesn't have any colour. For some reason, I can't add the legend title for the second line (the one that does not have colours). I've already tried using labs(fill) and labs (shape). Any clue?enter image description here

I am using the the following code for a chart:

ggplot() 
  geom_line(data=Flow %>% 
              filter((motivo=="Tourism"|motivo=="Transit") & flujo=="Exits"))
            aes(x=date, color=destino_procedencia, text = paste(
              "People:", ..count..,
              "<br>Date: ", format(as.Date(..x.., origin = "1970-01-01"), "%Y (%b)"),
              "<br>Type of Flow: ", ..color..
            )), stat="count") 
  geom_line(data=Net_migration, 
            aes(x=date,
                y=Saldo, text = paste(
                  "People:", ..y..,
                  "<br>Date: ", format(as.Date(..x.., origin = "1970-01-01"), "%Y (%b)")
                ))) 
  labs(color="Country of Destination", fill="Net Migration") 
  ggtitle("Number of Exits and Net Migration Rates, by Month and Destination, Venezuelan Nationals,Colombia, 2017-2021") 
  xlab("Date") 
  ylab("Number or People")
ggplotly(tooltip = c("text"))

enter image description here

CodePudding user response:

Have you tried to manually fill the aesthetics color with the value that you want?

See the section 11.7 of Wickham's book ggplot2: elegant graphics for data analysis. By the way, this book is amazing!

  • Related