dolphins

references:
- ISI, example 5.2, p.267

library(tidyverse)

data

dolphins <- read.csv("Dolphin1.txt")
str(dolphins)
## 'data.frame':    30 obs. of  2 variables:
##  $ Swimming: Factor w/ 2 levels "Control","Dolphin": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Response: Factor w/ 2 levels "Improve","NotImprove": 1 1 1 1 1 1 1 1 1 1 ...
tbl <- dolphins %>%
  group_by(Swimming, Response) %>%
  summarize(n = n())
tbl
## # A tibble: 4 x 3
## # Groups:   Swimming [?]
##   Swimming   Response     n
##     <fctr>     <fctr> <int>
## 1  Control    Improve     3
## 2  Control NotImprove    12
## 3  Dolphin    Improve    10
## 4  Dolphin NotImprove     5

Bar plot.

ggplot(tbl, aes(x = Swimming, Response, y = n, fill = Response)) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = c("aquamarine", "burlywood")) +
  labs(title = "Dolphins")