In-class 2

pacman::p_load(tidyverse, ggdist, ggthemes, ggridges, colorspace)
exam_df <- read_csv("../data/Exam_data.csv")
Rows: 322 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (4): ID, CLASS, GENDER, RACE
dbl (3): ENGLISH, MATHS, SCIENCE

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
ggplot(exam_df, aes(x=ENGLISH)) +
  geom_histogram(color = "#1696d2",
               adjust = 0.65,
               alpha = 0.6)
Warning in geom_histogram(color = "#1696d2", adjust = 0.65, alpha = 0.6):
Ignoring unknown parameters: `adjust`
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(exam_df, aes(x=ENGLISH)) +
  geom_density(color = "#1696d2",
               adjust = 0.65,
               alpha = 0.6,)

median_eng <- median(exam_df$ENGLISH)
mean_eng <- mean(exam_df$ENGLISH)
std_eng <- sd(exam_df$ENGLISH)

ggplot(exam_df, aes(x=ENGLISH)) +
  geom_density(color = "#1696d2",
               adjust = 0.65,
               alpha = 0.6,) +
  stat_function(
    fun=dnorm,
    args = list(mean=mean_eng, sd = std_eng),
    col = "grey30",
    size = 0.8)+
    geom_vline(aes(xintercept=mean_eng), color = "#4d5887", linewidth = 0.6, linetype = "dashed")+
  annotate(geom = "text",
           x = mean_eng - 10,
           y = 0.04,
           label = paste0("Mean ENGLISH:", round(mean_eng), 2),
           color = "#4d5887") +
  geom_vline(aes(xintercept=median_eng), color = "#4d5887", linewidth = 0.6) +
  annotate(geom = "text",
           x = median_eng + 10,
           y = 0.04,
           label = paste0("Median ENGLISH:", round(median_eng), 2),
           color = "#4d5887")
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.