acupuncture

references:
- ISI, example 8.2, p.441
- An Introduction to reshape2, Sean C. Anderson

library(tidyverse)
library(reshape2)   # melt and cast

simulation

data

acupuncture <- read.csv("Acupuncture.csv")
str(acupuncture)
## 'data.frame':    1162 obs. of  2 variables:
##  $ Acupuncture: Factor w/ 3 levels "None","Real",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ Improvement: Factor w/ 2 levels "Better","Not": 1 1 1 1 1 1 1 1 1 1 ...
tbl <- acupuncture %>%
  group_by(Acupuncture, Improvement) %>%
  summarize(n = n())
tbl
## # A tibble: 6 x 3
## # Groups:   Acupuncture [?]
##   Acupuncture Improvement     n
##        <fctr>      <fctr> <int>
## 1        None      Better   106
## 2        None         Not   282
## 3        Real      Better   184
## 4        Real         Not   203
## 5        Sham      Better   171
## 6        Sham         Not   216

Bar plot.

ggplot(tbl, aes(x = Acupuncture, Improvement, y = n, fill = Improvement)) +
  geom_bar(stat = "identity", position = "fill") +
  scale_fill_manual(values = c("papayawhip", "peru")) +
  labs(title = "Acupuncture")