Exercise 1.1: Scatterplot
ggplot(crampton.pig, aes(weight1, weight2, color = treatment, size = feed)) +
geom_point()
Exercise 1.2: Tile plot
ggplot(crampton.pig, aes(rep, treatment, fill = weight2 - weight1)) +
geom_tile(color = "black", size = 2)
Exercise 1.3: Density plot
ggplot(crampton.pig, aes(weight2 - weight1, fill = treatment)) +
geom_density(alpha = 0.7)
Exercise 1.4: Grouped barplot
ggplot(crampton.pig, aes(treatment, feed, fill = rep)) +
geom_col(position = "dodge")
Exercise 1.5: Rose plot
ggplot(crampton.pig, aes(treatment, feed, fill = rep)) +
geom_col(position = "dodge") + coord_polar("x")
Exercise 1.6: Boxplot
ggplot(heart2, aes(heart_disease, obesity, fill = family_history)) +
geom_boxplot()
Exercise 1.7: Dotplot
ggplot(heart2, aes(heart_disease, obesity, fill = family_history)) +
geom_dotplot(binaxis = "y", stackdir = "center",
position = "dodge")
## Bin width defaults to 1/30 of the range of the data. Pick better value with `binwidth`.
Exercise 1.8: Violin plot
ggplot(heart2, aes(heart_disease, obesity, fill = family_history)) +
geom_violin()
Exercise 1.9: 2D density plot
ggplot(heart2, aes(age, obesity)) +
geom_density_2d_filled()
Exercise 1.10: Hexagonal heatmap
ggplot(heart2, aes(age, obesity)) +
geom_hex()