geom
sPush the knit
button!
library(tidyverse) # contains ggplot2, dplyr, tidyr, etc
library(agridat) # for `crampton.pig` data
library(catdata) # for `heart` data
crampton.pig
datasetglimpse(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, …
# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(crampton.pig, aes(weight1, weight2, color = ..., size = ...)) +
geom_point()
# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(crampton.pig, aes(..., ..., fill = ...)) +
geom_tile(color = "black", size = 2)
# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(crampton.pig, aes(..., fill = ...)) +
geom_density(alpha = 0.7)
# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(crampton.pig, aes(..., ..., fill = ...)) +
geom_col(position = "dodge")
# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(crampton.pig, aes(..., ..., fill = ...)) +
geom_col(position = "dodge") + coord_polar("x")
heart
datasetdata("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…
# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(heart2, aes(..., ..., fill = ...)) +
geom_boxplot()
# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(heart2, aes(..., ..., fill = ...)) +
geom_dotplot(binaxis = "y", stackdir = "center",
position = "dodge")
# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(heart2, aes(..., ..., fill = ...)) +
geom_violin()
# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(heart2, aes(..., ...)) +
geom_density_2d_filled()
# fill all ... and change eval = FALSE to eval = TRUE when done
ggplot(heart2, aes(..., ...)) +
geom_hex()