0

i am trying to combine a geom_bar and geom_line however, my geom_line does not seem to be showing. It ends up with this error: geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?

Here is my code:

delay.df %>% ggplot() + geom_bar(aes(x = AIRLINE, y = TOTAL_DELAYS), stat = "identity") + geom_line(aes(x = AIRLINE, y = DELAY_PERCENTAGE), size = 1, colour = "blue") 

It ends up only showing the geom_bar. I have checked and both the TOTAL_DELAYS and DELAY_PERCENTAGE are numericals.

Here is the table in R: delay.df

  • To help us to help would you mind sharing [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data. To share your data, you could type `dput(NAME_OF_DATASET)` into the console and copy & paste the output starting with `structure(....` into your post. If your dataset has a lot of observations you could do e.g. `dput(head(NAME_OF_DATASET, 20))` for the first twenty rows of data. – stefan Nov 01 '21 at 09:21
  • 1
    .... but you could try by providing the group aes, i.e. do `geom_line(aes(x = AIRLINE, y = DELAY_PERCENTAGE, group = 1)`. Otherwise each AIRLINE is treated as a separate group with only one obs and hence no line shows up. – stefan Nov 01 '21 at 09:22
  • For a more detailed explanation see https://stackoverflow.com/questions/10357768/plotting-lines-and-the-group-aesthetic-in-ggplot2 – stefan Nov 01 '21 at 09:24

0 Answers0