Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206531

How to add mean (or median) line to geom_bar?

$
0
0

I need to add mean or median to a bar plot, don't know why it doesn't work:

      data_GP %>%
      group_by(Customer, Year, Customer_category) %>%
      dplyr::summarise(GP_value = mean(GP),
                       REV_value = mean(REV),
                       GP_percent = mean(GP)/mean(REV)) %>%

      filter(., GP_percent > -1, Customer_category == "regular", Year == 2019) %>%
      ggplot(.,aes(x = Customer, y = GP_value)) +
      stat_summary(fun.y=mean, geom="line") +
      geom_bar(alpha = 0.5, stat = "identity")

So, basically I would like to show one line on a geom_bar showing mean (or median) value for all observations. Error comes up and goes:

geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?


Viewing all articles
Browse latest Browse all 206531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>