blood

references:
- ISI, exploration 5.3, p.291

library(tidyverse)
library(knitr)

simulation

data

blood <- read.delim("Blood.txt", header = TRUE)
str(blood)
## 'data.frame':    2698 obs. of  2 variables:
##  $ Year    : int  2002 2002 2002 2002 2002 2002 2002 2002 2002 2002 ...
##  $ Response: Factor w/ 2 levels "did.not","donated": 2 2 2 2 2 2 2 2 2 2 ...
tbl <- blood %>%
  group_by(Year, Response) %>%
  summarize(n = n())
tbl
## # A tibble: 4 x 3
## # Groups:   Year [?]
##    Year Response     n
##   <int>   <fctr> <int>
## 1  2002  did.not  1152
## 2  2002  donated   210
## 3  2004  did.not  1106
## 4  2004  donated   230

Bar plot.

ggplot(tbl, aes(x = Year, Response, y = n, fill = Response)) +
  geom_bar(stat = "identity", position = "fill") +
  scale_fill_manual(values = c("mintcream", "turquoise")) +
  labs(title = "Donating Blood")