Home > Software design >  Make a line separated by group in bar chart in GGplot
Make a line separated by group in bar chart in GGplot

Time:12-29

I am trying to overlay two sets of data that with be used in bar charts. The first is the main set of data and I want that to be the main focus. For the second dataset I want just a line marking where on the chart it would be. I can get close to what I want by doing this:

Tbl = data.frame(Factor = c("a","b","c","d"),
                 Percent = c(43,77,37,55))

Tbl2 = data.frame(Factor = c("a","b","c","d"),
                  Percent = c(58,68,47,63))

ggplot(aes(x = Factor, y = Percent), data = Tbl)   
  geom_bar(position = "stack", stat = "identity", fill = "blue")  
  ylim(0,100)  
  geom_bar(aes(x = Factor, y = Percent), data = Tbl2,
           position = "stack", stat = "identity", fill = NA, color = "black")  
  theme_bw()

enter image description here

  • Related