Home > Software design >  apply pallete in geom_bar ggplot
apply pallete in geom_bar ggplot

Time:07-09

I am trying to apply a pallete to a geom_bar with facets.

Here is my code

est21 <- structure(list(Zona = c("Urbana", "Urbana", "Urbana", "Rural", 
"Urbana", "Urbana", "Urbana", "Rural", "Rural", "Urbana", "Rural", 
"Urbana", "Rural", "Urbana", "Urbana", "Urbana", "Rural", "Urbana", 
"Urbana", "Urbana"), Sector = c("Pública", "Pública", "Pública", 
"Pública", "Pública", "CECE", "Pública", "Pública", "Pública", 
"Privada", "Pública", "Privada", "Pública", "Pública", "Pública", 
"Pública", "Pública", "CECE", "Privada", "Pública")), row.names = c(NA, 
20L), class = "data.frame")

ggplot(est21, aes(as.factor(Sector))) 
  geom_bar(width = 0.5, , fill = '#5081ac')  
  xlab('X')  
  ylab('Y')  
  facet_wrap(~Zona)  
  theme(axis.line = element_line(colour = 'black'),
        panel.background = element_blank(),
        axis.text = element_text(size = 18),
        axis.title = element_text(size = 20),
        panel.grid.major.y = element_line(colour = 'gray'),
        panel.grid.minor.y = element_line(colour = 'gray'),
        plot.title = element_text(hjust = 0.5,
                                  size = 20),
        text = element_text(family = 'Sans'))  
  scale_y_continuous(expand = c(0, 0), limits = c(0, 7500))  
  geom_text(aes(label = scales::percent(prop.table(stat(count)))),
            stat= "count",
            vjust = -.5,
            size = 7)  
  labs(title = 'Proof')

I want a plot like this where the same pallete is used for the facets. Plot

CodePudding user response:

The enter image description here

  • Related