Push the knit button!

library(tidyverse) # contains ggplot2, dplyr, tidyr, etc
library(agridat) # for `crampton.pig` data
library(catdata) # for `heart` data

crampton.pig dataset

glimpse(crampton.pig)
## Rows: 50
## Columns: 5
## $ treatment <fct> T1, T1, T1, T1, T1, T1, T1, T1, T1, T1, T2, T2, T2, T2, T2, …
## $ rep       <fct> R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R1, R2, R3, R4, R5,…
## $ weight1   <int> 30, 21, 21, 33, 27, 24, 20, 29, 28, 26, 26, 24, 20, 35, 25, …
## $ feed      <int> 674, 628, 661, 694, 713, 585, 575, 638, 632, 637, 699, 626, …
## $ weight2   <int> 195, 177, 180, 200, 197, 170, 150, 180, 192, 184, 194, 204, …

Exercise 1.1: Scatterplot

# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(crampton.pig, aes(weight1, weight2, color = ..., size = ...)) + 
  geom_point()

Exercise 1.2: Tile plot

# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(crampton.pig, aes(..., ..., fill = ...)) + 
  geom_tile(color = "black", size = 2)

Exercise 1.3: Density plot

# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(crampton.pig, aes(..., fill = ...)) + 
  geom_density(alpha = 0.7) 

Exercise 1.4: Grouped barplot

# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(crampton.pig, aes(..., ..., fill = ...)) + 
  geom_col(position = "dodge")

Exercise 1.5: Rose plot

# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(crampton.pig, aes(..., ..., fill = ...)) + 
  geom_col(position = "dodge") + coord_polar("x")

heart dataset

data("heart")
# cleaning a bit of the `heart` data
heart2 <- heart %>% 
  as_tibble(heart) %>% 
  mutate(family_history = ifelse(famhist==1, "Yes", "No"),
         heart_disease = ifelse(y==1, "Yes", "No"))

glimpse(heart2)
## Rows: 462
## Columns: 12
## $ y              <dbl> 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1…
## $ sbp            <dbl> 160, 144, 118, 170, 134, 132, 142, 114, 114, 132, 206, …
## $ tobacco        <dbl> 12.00, 0.01, 0.08, 7.50, 13.60, 6.20, 4.05, 4.08, 0.00,…
## $ ldl            <dbl> 5.73, 4.41, 3.48, 6.41, 3.50, 6.47, 3.38, 4.59, 3.83, 5…
## $ adiposity      <dbl> 23.11, 28.61, 32.28, 38.03, 27.78, 36.21, 16.20, 14.60,…
## $ famhist        <dbl> 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1…
## $ typea          <dbl> 49, 55, 52, 51, 60, 62, 59, 62, 49, 69, 72, 65, 59, 49,…
## $ obesity        <dbl> 25.30, 28.87, 29.14, 31.99, 25.99, 30.77, 20.81, 23.11,…
## $ alcohol        <dbl> 97.20, 2.06, 3.81, 24.26, 57.34, 14.14, 2.62, 6.72, 2.4…
## $ age            <dbl> 52, 63, 46, 58, 49, 45, 38, 58, 29, 53, 60, 40, 17, 15,…
## $ family_history <chr> "Yes", "No", "Yes", "Yes", "Yes", "Yes", "No", "Yes", "…
## $ heart_disease  <chr> "Yes", "Yes", "No", "Yes", "Yes", "No", "No", "Yes", "N…

Exercise 1.6: Boxplot

# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(heart2, aes(..., ..., fill = ...)) + 
  geom_boxplot()

Exercise 1.7: Dotplot

# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(heart2, aes(..., ..., fill = ...)) + 
  geom_dotplot(binaxis = "y", stackdir = "center",
               position = "dodge")

Exercise 1.8: Violin plot

# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(heart2, aes(..., ..., fill = ...)) + 
  geom_violin()

Exercise 1.9: 2D density plot

# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(heart2, aes(..., ...)) + 
  geom_density_2d_filled()

Exercise 1.10: Hexagonal heatmap

# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(heart2, aes(..., ...)) + 
  geom_hex()