Creating a Layered Bar Chart in RStudio

Hello, I have the following dataset:

 Infection Type Observed Disease Incidence (% Infected Heads)

1 Bt0 (control) 0%
2 Bt0 (D-19) 41%
3 Bt0 (L-18) 67%
4 Bt0 (T-33) 67%
5 Bt0 (T-35) 63%
6 IDO444 (L-18) 0%
7 PI178210 (L-18) 76%
8 PI178210 (D-19) 0%
9 PI554120 (L-18) 0%
10 PI554120 (D-19) 45%
11 Rio Blanco (L-18) 0%
12 Rio Blanco (T-13) 0%
13 Rio Blanco (T-33) 0%
14 Rio Blanco (T-35) 100%
15 UI Sparrow (control) 0%
16 UI Sparrow (D-19) 0%
17 UI Sparrow (T-33) 0%
18 WA8268 (D-19) 18%
Expected Disease Incidence (% Infected Heads)
1 100%
2 100%
3 100%
4 100%
5 100%
6 0%
7 100%
8 0%
9 100%
10 100%
11 100%
12 100%
13 100%
14 100%
15 0%
16 0%
17 0%
18 100%

I want to layer the observed disease incidence over the expected disease incidence in a bar chart. Any ideas for how to do this? Stacking would be inappropriate for this dataset because it's not additive.

Thanks!

Is this the sort of thing you are looking for?

library(ggplot2)

DF <- data.frame(Name = c("A", "A", "B", "B", "C", "C"),
                 Type = c("Expect", "Obs", "Expect", "Obs", "Expect", "Obs"),
                 Value = c(60, 40, 70, 65, 50, 20)) 
DF
#>   Name   Type Value
#> 1    A Expect    60
#> 2    A    Obs    40
#> 3    B Expect    70
#> 4    B    Obs    65
#> 5    C Expect    50
#> 6    C    Obs    20

ggplot(mapping = aes(fill = Type)) + 
  geom_col(aes(Name, Value), alpha = 0.5, data = filter(DF, Type == "Expect")) +
  geom_col(aes(Name, Value), alpha = 0.5, data = filter(DF, Type == "Obs"))

Created on 2019-12-22 by the reprex package (v0.3.0.9000)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.