Cloud Stack Ninja

How to add a line with total number of individuals (or even better, shade the area under that line as background) to each graph being produced by:

library(ggplot2)
library(readxl)
library(dplyr)
library(RColorBrewer)
        
         dataset %>% 
    ggplot(.,aes(x=factor(PovertyDecile),y=Nr_Individuals,fill=factor(PovertyDecile))) + 
                geom_col() +
                facet_wrap(~ office)+
                scale_fill_brewer(palette = "RdYlGn")+
                theme_classic()+
                theme(
                  strip.background = element_blank(),
                  strip.text.x = element_blank()
                )

I tried many versions of geom_hline but none worked.

My dataset is:

region   office    Nr_Individuals    total_Nr_Individuals    PovertyDecile   weighted_PovDecile
   1       A             80                 105                   2                2.5
   1       A             23                 105                   3                2.5
   1       B             2                  105                   4                4
   2       C             100                160                   1                1.5   
   2       C             60                 160                   2                1.5
   3       D             20                 70                    8                9
   3       D             50                 70                    10               9

what I am getting using #code4 (any thoughts?): enter image description here

without gray option: enter image description here



Read more here: https://stackoverflow.com/questions/64418732/how-to-add-line-to-geom-col-in-r

Content Attribution

This content was originally published by Daniela Rodrigues at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: