getwd()
## [1] "C:/Users/User/OneDrive/Research/Puberty Delinquency(HRB)"
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readr)
library(haven)
library(readxl)


# early
early_int <- read_excel("./4. sas print files/early_int.xlsx") %>%
    rename(Grade = n_year_2, early = Intercept,
           e_l = Intercept_L, e_u = Intercept_U) %>%
    mutate(Grade = Grade - 2003) %>% # convert time
    mutate(early = exp(early), # convert into proportion
           e_l = exp(e_l),
           e_u = exp(e_u)) %>%
    select(-Intercept_SE)
# on time
normal_int <- read_excel("./4. sas print files/normal_int.xlsx") %>%
    rename(Grade = n_year_2, normal = Intercept,
           n_l = Intercept_L, n_u = Intercept_U) %>%
    mutate(Grade = Grade - 2003) %>%
    mutate(normal = exp(normal),
           n_l = exp(n_l),
           n_u = exp(n_u)) %>%
    select(-Intercept_SE)
# late
late_int <- read_excel("./4. sas print files/late_int.xlsx") %>%
    rename(Grade = n_year_2, late = Intercept,
           l_l = Intercept_L, l_u = Intercept_U) %>%
    mutate(Grade = Grade - 2003) %>%
    mutate(late = exp(late),
           l_l = exp(l_l),
           l_u = exp(l_u)) %>%
    select(-Intercept_SE)

intercept <- early_int %>% 
    left_join(normal_int, by = c("Grade")) %>%
    left_join(late_int, by = c("Grade"))


colors <- c("late" = "#0000CC",
            "early" = "#CC0000",
            "on time" = "#1B9E77")
linetypes <- c("late" = 5,
               "early" = 1,
               "on time" = 6)


# 1. Intercept

ggplot(intercept) +
    aes(x = Grade) +
    geom_line(aes(y = early, color = "early", lty = "early"), size = 1) +
    geom_line(aes(y = normal, color = "on time", lty = "on time"), size = 1) +
    geom_line(aes(y = late, color = "late", lty = "late"), size = 1) +
    geom_ribbon(aes(ymin = e_l, ymax = e_u), color = "#CC0000", alpha = 0.05, lty = "dotted") +
    geom_ribbon(aes(ymin = n_l, ymax = n_u), color = "#1B9E77", alpha = 0.05, lty = "dotted") +
    geom_ribbon(aes(ymin = l_l, ymax = l_u), color = "#0000CC", alpha = 0.05, lty = "dotted") +
    theme_bw() +
    scale_color_manual(values = colors) +
    scale_linetype_manual(values = linetypes) + 
    labs(x = "Grade"
         , y = "Prevalence"
         , color = "Puberty Group"
         , lty = "Puberty Group") +
    theme(legend.position = "bottom",
          plot.title = element_text(family = "Times", size = (16)),
          legend.title = element_text(family = "Times", size = (16)),
          legend.text = element_text(family = "Times", size = (16)),
          axis.title = element_text(family = "Times", size = (16)),
          axis.text = element_text(family = "Times", size = (16)))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): 윈도우즈
## 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

## Only E and L
ggplot(intercept) +
    aes(x = Grade) +
    geom_line(aes(y = early, color = "early", lty = "early"), size = 1) +
    geom_line(aes(y = late, color = "late", lty = "late"), size = 1) +
    geom_ribbon(aes(ymin = e_l, ymax = e_u), color = "#CC0000", alpha = 0.1, lty = "dotted") +
    geom_ribbon(aes(ymin = l_l, ymax = l_u), color = "#0000CC", alpha = 0.1, lty = "dotted") +
    theme_bw() +
    scale_color_manual(values = colors
                       , limits = c("early", "late")) +
    labs(x = "Grade"
         , y = "Prevalence"
         , lty = "Puberty Group"
         , color = "Puberty Group") +
    theme(legend.position = "bottom",
          plot.title = element_text(family = "Times", size = (16)),
          legend.title = element_text(family = "Times", size = (16)),
          legend.text = element_text(family = "Times", size = (16)),
          axis.title = element_text(family = "Times", size = (16)),
          axis.text = element_text(family = "Times", size = (16)))
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

# 2. Peer Substance Abuse
early_cov <- read_excel("./4. sas print files/early_covariates.xlsx") %>%
    rename(Grade = n_year_2) %>%
    mutate(Grade = Grade - 2003) 
normal_cov <- read_excel("./4. sas print files/normal_covariates.xlsx") %>%
    rename(Grade = n_year_2) %>%
    mutate(Grade = Grade - 2003)
late_cov <- read_excel("./4. sas print files/late_covariates.xlsx") %>%
    rename(Grade = n_year_2) %>%
    mutate(Grade = Grade - 2003)

ggplot() +
    geom_line(aes(x = early_cov$Grade, y = early_cov$n_peer_all_2, 
                  color = "early", lty = "early"), size = 1) +
    geom_line(aes(x = normal_cov$Grade, y = normal_cov$n_peer_all_2, 
                  color = "on time", lty = "on time"), size = 1) +
    geom_line(aes(x = late_cov$Grade, y = late_cov$n_peer_all_2, 
                  color = "late", lty = "late"), size = 1) +
    geom_hline(yintercept = 0, color = "black") +
    geom_ribbon(aes(x = early_cov$Grade,
                    ymin = early_cov$n_peer_all_2_L, ymax = early_cov$n_peer_all_2_U), 
                color = "#CC0000", alpha = 0.04, lty = "dotted") +
    geom_ribbon(aes(x = normal_cov$Grade, 
                    ymin = normal_cov$n_peer_all_2_L, ymax = normal_cov$n_peer_all_2_U), 
                color = "#1B9E77", alpha = 0.04, lty = "dotted") +
    geom_ribbon(aes(x = late_cov$Grade,
                    ymin = late_cov$n_peer_all_2_L, ymax = late_cov$n_peer_all_2_U), 
                color = "#0000CC", alpha = 0.04, lty = "dotted") +
    theme_bw() +
    scale_color_manual(values = colors
                       , limits = c("early", "late", "on time")) +
    labs(x = "Grade"
         , y = "Coefficient"
         , lty = "Puberty Group"
         , color = "Puberty Group") +
    theme(legend.position = "bottom",
          plot.title = element_text(family = "Times", size = (16)),
          legend.title = element_text(family = "Times", size = (16)),
          legend.text = element_text(family = "Times", size = (16)),
          axis.title = element_text(family = "Times", size = (16)),
          axis.text = element_text(family = "Times", size = (16))) 
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

## E and L only
ggplot() +
    geom_line(aes(x = early_cov$Grade, y = early_cov$n_peer_all_2, 
                  color = "early", lty = "early"), size = 1) +
    geom_line(aes(x = late_cov$Grade, y = late_cov$n_peer_all_2, 
                  color = "late", lty = "late"), size = 1) +
    geom_hline(yintercept = 0, color = "black") +
    geom_ribbon(aes(x = early_cov$Grade,
                    ymin = early_cov$n_peer_all_2_L, ymax = early_cov$n_peer_all_2_U), 
                color = "#CC0000", alpha = 0.04, lty = "dotted") +
    geom_ribbon(aes(x = late_cov$Grade,
                    ymin = late_cov$n_peer_all_2_L, ymax = late_cov$n_peer_all_2_U), 
                color = "#0000CC", alpha = 0.04, lty = "dotted") +
    theme_bw() +
    scale_color_manual(values = colors
                       ,limits = c("early", "late")) +
    labs(x = "Grade"
         , y = "Coefficient"
         , lty = "Puberty Group"
         , color = "Puberty Group") +
    theme(legend.position = "bottom",
          plot.title = element_text(family = "Times", size = (16)),
          legend.title = element_text(family = "Times", size = (16)),
          legend.text = element_text(family = "Times", size = (16)),
          axis.title = element_text(family = "Times", size = (16)),
          axis.text = element_text(family = "Times", size = (16))) 
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

# 3. Parent Attachment

ggplot() +
    geom_line(aes(x = early_cov$Grade, y = early_cov$n_P_attach_2, 
                  color = "early", lty = "early"), size = 1) +
    geom_line(aes(x = normal_cov$Grade, y = normal_cov$n_P_attach_2, 
                  color = "on time", lty = "on time"), size = 1) +
    geom_line(aes(x = late_cov$Grade, y = late_cov$n_P_attach_2, 
                  color = "late", lty = "late"), size = 1) +
    geom_hline(yintercept = 0, color = "black") +
    geom_ribbon(aes(x = early_cov$Grade,
                    ymin = early_cov$n_P_attach_2_L, ymax = early_cov$n_P_attach_2_U), 
                color = "#CC0000", alpha = 0.04, lty = "dotted") +
    geom_ribbon(aes(x = normal_cov$Grade, 
                    ymin = normal_cov$n_P_attach_2_L, ymax = normal_cov$n_P_attach_2_U), 
                color = "#1B9E77", alpha = 0.04, lty = "dotted") +
    geom_ribbon(aes(x = late_cov$Grade,
                    ymin = late_cov$n_P_attach_2_L, ymax = late_cov$n_P_attach_2_U), 
                color = "#0000CC", alpha = 0.04, lty = "dotted") +
    theme_bw() +
    scale_color_manual(values = colors
                       , limits = c("early", "late", "on time")) +
    labs(x = "Grade"
         , y = "Coefficient"
         , lty = "Puberty Group"
         , color = "Puberty Group") +
    theme(legend.position = "bottom",
          plot.title = element_text(family = "Times", size = (16)),
          legend.title = element_text(family = "Times", size = (16)),
          legend.text = element_text(family = "Times", size = (16)),
          axis.title = element_text(family = "Times", size = (16)),
          axis.text = element_text(family = "Times", size = (16))) 
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

## E and L only
ggplot() +
    geom_line(aes(x = early_cov$Grade, y = early_cov$n_P_attach_2, 
                  color = "early", lty = "early"), size = 1) +
    geom_line(aes(x = late_cov$Grade, y = late_cov$n_P_attach_2, 
                  color = "late", lty = "late"), size = 1) +
    geom_hline(yintercept = 0, color = "black") +
    geom_ribbon(aes(x = early_cov$Grade,
                    ymin = early_cov$n_P_attach_2_L, ymax = early_cov$n_P_attach_2_U), 
                color = "#CC0000", alpha = 0.04, lty = "dotted") +
    geom_ribbon(aes(x = late_cov$Grade,
                    ymin = late_cov$n_P_attach_2_L, ymax = late_cov$n_P_attach_2_U), 
                color = "#0000CC", alpha = 0.04, lty = "dotted") +
    theme_bw() +
    scale_color_manual(values = colors
                       ,limits = c("early", "late")) +
    labs(x = "Grade"
         , y = "Coefficient"
         , lty = "Puberty Group"
         , color = "Puberty Group") +
    theme(legend.position = "bottom",
          plot.title = element_text(family = "Times", size = (16)),
          legend.title = element_text(family = "Times", size = (16)),
          legend.text = element_text(family = "Times", size = (16)),
          axis.title = element_text(family = "Times", size = (16)),
          axis.text = element_text(family = "Times", size = (16))) 
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

# 4. Coeducation

ggplot() +
    geom_line(aes(x = early_cov$Grade, y = early_cov$n_coedu_1, 
                  color = "early", lty = "early"), size = 1) +
    geom_line(aes(x = normal_cov$Grade, y = normal_cov$n_coedu_1, 
                  color = "on time", lty = "on time"), size = 1) +
    geom_line(aes(x = late_cov$Grade, y = late_cov$n_coedu_1, 
                  color = "late", lty = "late"), size = 1) +
    geom_hline(yintercept = 0, color = "black") +
    geom_ribbon(aes(x = early_cov$Grade,
                    ymin = early_cov$n_coedu_1_L, ymax = early_cov$n_coedu_1_U), 
                color = "#CC0000", alpha = 0.04, lty = "dotted") +
    geom_ribbon(aes(x = normal_cov$Grade, 
                    ymin = normal_cov$n_coedu_1_L, ymax = normal_cov$n_coedu_1_U), 
                color = "#1B9E77", alpha = 0.04, lty = "dotted") +
    geom_ribbon(aes(x = late_cov$Grade,
                    ymin = late_cov$n_coedu_1_L, ymax = late_cov$n_coedu_1_U), 
                color = "#0000CC", alpha = 0.04, lty = "dotted") +
    theme_bw() +
    scale_color_manual(values = colors
                       , limits = c("early", "late", "on time")) +
    labs(x = "Grade"
         , y = "Coefficient"
         , lty = "Puberty Group"
         , color = "Puberty Group") +
    theme(legend.position = "bottom",
          plot.title = element_text(family = "Times", size = (16)),
          legend.title = element_text(family = "Times", size = (16)),
          legend.text = element_text(family = "Times", size = (16)),
          axis.title = element_text(family = "Times", size = (16)),
          axis.text = element_text(family = "Times", size = (16))) 
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

## E and L only
ggplot() +
    geom_line(aes(x = early_cov$Grade, y = early_cov$n_coedu_1, 
                  color = "early", lty = "early"), size = 1) +
    geom_line(aes(x = late_cov$Grade, y = late_cov$n_coedu_1, 
                  color = "late", lty = "late"), size = 1) +
    geom_hline(yintercept = 0, color = "black") +
    geom_ribbon(aes(x = early_cov$Grade,
                    ymin = early_cov$n_coedu_1_L, ymax = early_cov$n_coedu_1_U), 
                color = "#CC0000", alpha = 0.04, lty = "dotted") +
    geom_ribbon(aes(x = late_cov$Grade,
                    ymin = late_cov$n_coedu_1_L, ymax = late_cov$n_coedu_1_U), 
                color = "#0000CC", alpha = 0.04, lty = "dotted") +
    theme_bw() +
    scale_color_manual(values = colors
                       ,limits = c("early", "late")) +
    labs(x = "Grade"
         , y = "Coefficient"
         , lty = "Puberty Group"
         , color = "Puberty Group") +
    theme(legend.position = "bottom",
          plot.title = element_text(family = "Times", size = (16)),
          legend.title = element_text(family = "Times", size = (16)),
          legend.text = element_text(family = "Times", size = (16)),
          axis.title = element_text(family = "Times", size = (16)),
          axis.text = element_text(family = "Times", size = (16))) 
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

# 5. Overall Group - Intercept

# Intercept
T_int <- read_excel("./4. sas print files/total_intercept.xlsx") %>%
    rename(Grade = n_year_2) %>%
    mutate(Grade = Grade - 2003) %>% # convert time
    mutate(total = exp(Intercept), # convert into proportion
           t_l = exp(Intercept_L),
           t_u = exp(Intercept_U)) %>%
    select(-Intercept_SE)
ggplot(T_int) +
    aes(x = Grade) +
    geom_line(aes(y = total), size = 1) +
    geom_line(aes(y = 0), size = 1) +
    geom_ribbon(aes(ymin = t_l, ymax = t_u), color = "#CC0000", alpha = 0.04, lty = "dotted") +
    theme_bw() +
    labs(x = "Grade"
         , y = "Prevalence"
         , title = ""
         , lty = "Puberty Group"
         , color = "Puberty Group") +
    theme(legend.position = "bottom",
          plot.title = element_text(family = "Times", size = (16)),
          legend.title = element_text(family = "Times", size = (16)),
          legend.text = element_text(family = "Times", size = (16)),
          axis.title = element_text(family = "Times", size = (16)),
          axis.text = element_text(family = "Times", size = (16)))
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

# 6. Overall Group - Covariates
T_cov <- read_excel("./4. sas print files/total_covariate.xlsx") %>%
    rename(Grade = n_year_2) %>%
    mutate(Grade = Grade - 2003)

# Peer Substance Use
ggplot(T_cov) +
    aes(x = Grade) +
    geom_line(aes(y = n_peer_all_2), size = 1) +
    geom_line(aes(y = 0), size = 1, color = "grey50") +
    geom_ribbon(aes(ymin = n_peer_all_2_L, ymax = n_peer_all_2_U), color = "#CC0000", alpha = 0.04, lty = "dotted") +
    theme_bw() +
    labs(x = "Grade"
         , y = "Coefficient"
         , title = ""
         , lty = "Puberty Group"
         , color = "Puberty Group") +
    theme(legend.position = "bottom",
          plot.title = element_text(family = "Times", size = (16)),
          legend.title = element_text(family = "Times", size = (16)),
          legend.text = element_text(family = "Times", size = (16)),
          axis.title = element_text(family = "Times", size = (16)),
          axis.text = element_text(family = "Times", size = (16)))
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

# Parent attachment
ggplot(T_cov) +
    aes(x = Grade) +
    geom_line(aes(y = n_P_attach_2), size = 1) +
    geom_line(aes(y = 0), size = 1, color = "grey50") +
    geom_ribbon(aes(ymin = n_P_attach_2_L, ymax = n_P_attach_2_U), color = "#CC0000", alpha = 0.04, lty = "dotted") +
    theme_bw() +
    labs(x = "Grade"
         , y = "Coefficient"
         , title = ""
         , lty = "Puberty Group"
         , color = "Puberty Group") +
    theme(legend.position = "bottom",
          plot.title = element_text(family = "Times", size = (16)),
          legend.title = element_text(family = "Times", size = (16)),
          legend.text = element_text(family = "Times", size = (16)),
          axis.title = element_text(family = "Times", size = (16)),
          axis.text = element_text(family = "Times", size = (16)))
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

# Coeducation
ggplot(T_cov) +
    aes(x = Grade) +
    geom_line(aes(y = n_coedu_1), size = 1) +
    geom_line(aes(y = 0), size = 1, color = "grey50") +
    geom_ribbon(aes(ymin = n_coedu_1_L, ymax = n_coedu_1_U), color = "#CC0000", alpha = 0.04, lty = "dotted") +
    theme_bw() +
    labs(x = "Grade"
         , y = "Coefficient"
         , title = ""
         , lty = "Puberty Group"
         , color = "Puberty Group") +
    theme(legend.position = "bottom",
    )

# 7. Covariate Intercept Models
# Peer Delinquency
## early
pe_early_int <- read_excel("./4. sas print files/peer_int.xlsx", sheet = "early") %>%
    rename(Grade = n_year_2, early = Intercept,
           e_l = Intercept_L, e_u = Intercept_U) %>%
    mutate(Grade = Grade - 2003) %>% # convert time
    mutate(early = (early), # convert into proportion
           e_l = (e_l),
           e_u = (e_u)) %>%
    select(-Intercept_SE)
## on time
pe_normal_int <- read_excel("./4. sas print files/peer_int.xlsx", sheet = "normal") %>%
    rename(Grade = n_year_2, normal = Intercept,
           n_l = Intercept_L, n_u = Intercept_U) %>%
    mutate(Grade = Grade - 2003) %>%
    mutate(normal = (normal),
           n_l = (n_l),
           n_u = (n_u)) %>%
    select(-Intercept_SE)
## late
pe_late_int <- read_excel("./4. sas print files/peer_int.xlsx", sheet = "late") %>%
    rename(Grade = n_year_2, late = Intercept,
           l_l = Intercept_L, l_u = Intercept_U) %>%
    mutate(Grade = Grade - 2003) %>%
    mutate(late = (late),
           l_l = (l_l),
           l_u = (l_u)) %>%
    select(-Intercept_SE)

pe_intercept <- pe_early_int %>% 
    left_join(pe_normal_int, by = c("Grade")) %>%
    left_join(pe_late_int, by = c("Grade"))

ggplot(pe_intercept) +
    aes(x = Grade) +
    geom_line(aes(y = early, color = "early", lty = "early"), size = 1) +
    geom_line(aes(y = normal, color = "on time", lty = "on time"), size = 1) +
    geom_line(aes(y = late, color = "late", lty = "late"), size = 1) +
    geom_ribbon(aes(ymin = e_l, ymax = e_u), color = "#CC0000", alpha = 0.05, lty = "dotted") +
    geom_ribbon(aes(ymin = n_l, ymax = n_u), color = "#1B9E77", alpha = 0.05, lty = "dotted") +
    geom_ribbon(aes(ymin = l_l, ymax = l_u), color = "#0000CC", alpha = 0.05, lty = "dotted") +
    theme_minimal() +
    scale_color_manual(values = colors) +
    scale_linetype_manual(values = linetypes) + 
    labs(x = "Grade"
         , y = "Exposure to Peer Delinquency"
         , color = "Puberty Group"
         , lty = "Puberty Group") +
    theme(legend.position = "bottom",
          plot.title = element_text(family = "Times", size = (16)),
          legend.title = element_text(family = "Times", size = (16)),
          legend.text = element_text(family = "Times", size = (16)),
          axis.title = element_text(family = "Times", size = (16)),
          axis.text = element_text(family = "Times", size = (16)))
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

# Parental Supervision
## early
pa_early_int <- read_excel("./4. sas print files/parent_int.xlsx", sheet = "early") %>%
    rename(Grade = n_year_2, early = Intercept,
           e_l = Intercept_L, e_u = Intercept_U) %>%
    mutate(Grade = Grade - 2003) %>% # convert time
    mutate(early = (early), # convert into proportion
           e_l = (e_l),
           e_u = (e_u)) %>%
    select(-Intercept_SE)
## on time
pa_normal_int <- read_excel("./4. sas print files/parent_int.xlsx", sheet = "normal") %>%
    rename(Grade = n_year_2, normal = Intercept,
           n_l = Intercept_L, n_u = Intercept_U) %>%
    mutate(Grade = Grade - 2003) %>%
    mutate(normal = (normal),
           n_l = (n_l),
           n_u = (n_u)) %>%
    select(-Intercept_SE)
## late
pa_late_int <- read_excel("./4. sas print files/parent_int.xlsx", sheet = "late") %>%
    rename(Grade = n_year_2, late = Intercept,
           l_l = Intercept_L, l_u = Intercept_U) %>%
    mutate(Grade = Grade - 2003) %>%
    mutate(late = (late),
           l_l = (l_l),
           l_u = (l_u)) %>%
    select(-Intercept_SE)

pa_intercept <- pa_early_int %>% 
    left_join(pa_normal_int, by = c("Grade")) %>%
    left_join(pa_late_int, by = c("Grade"))

ggplot(pa_intercept) +
    aes(x = Grade) +
    geom_line(aes(y = early, color = "early", lty = "early"), size = 1) +
    geom_line(aes(y = normal, color = "on time", lty = "on time"), size = 1) +
    geom_line(aes(y = late, color = "late", lty = "late"), size = 1) +
    geom_ribbon(aes(ymin = e_l, ymax = e_u), color = "#CC0000", alpha = 0.05, lty = "dotted") +
    geom_ribbon(aes(ymin = n_l, ymax = n_u), color = "#1B9E77", alpha = 0.05, lty = "dotted") +
    geom_ribbon(aes(ymin = l_l, ymax = l_u), color = "#0000CC", alpha = 0.05, lty = "dotted") +
    theme_minimal() +
    scale_color_manual(values = colors) +
    scale_linetype_manual(values = linetypes) + 
    labs(x = "Grade"
         , y = "Parental Supervision"
         , color = "Puberty Group"
         , lty = "Puberty Group") +
    theme(legend.position = "bottom",
          plot.title = element_text(family = "Times", size = (16)),
          legend.title = element_text(family = "Times", size = (16)),
          legend.text = element_text(family = "Times", size = (16)),
          axis.title = element_text(family = "Times", size = (16)),
          axis.text = element_text(family = "Times", size = (16)))
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

# Coeducation
## early
co_early_int <- read_excel("./4. sas print files/coedu_int.xlsx", sheet = "early") %>%
    rename(Grade = n_year_2, early = Intercept,
           e_l = Intercept_L, e_u = Intercept_U) %>%
    mutate(Grade = Grade - 2003) %>% # convert time
    mutate(early = (early), # convert into proportion
           e_l = (e_l),
           e_u = (e_u)) %>%
    select(-Intercept_SE)
## on time
co_normal_int <- read_excel("./4. sas print files/coedu_int.xlsx", sheet = "normal") %>%
    rename(Grade = n_year_2, normal = Intercept,
           n_l = Intercept_L, n_u = Intercept_U) %>%
    mutate(Grade = Grade - 2003) %>%
    mutate(normal = (normal),
           n_l = (n_l),
           n_u = (n_u)) %>%
    select(-Intercept_SE)
## late
co_late_int <- read_excel("./4. sas print files/coedu_int.xlsx", sheet = "late") %>%
    rename(Grade = n_year_2, late = Intercept,
           l_l = Intercept_L, l_u = Intercept_U) %>%
    mutate(Grade = Grade - 2003) %>%
    mutate(late = (late),
           l_l = (l_l),
           l_u = (l_u)) %>%
    select(-Intercept_SE)

co_intercept <- co_early_int %>% 
    left_join(co_normal_int, by = c("Grade")) %>%
    left_join(co_late_int, by = c("Grade"))

ggplot(co_intercept) +
    aes(x = Grade) +
    geom_line(aes(y = early, color = "early", lty = "early"), size = 1) +
    geom_line(aes(y = normal, color = "on time", lty = "on time"), size = 1) +
    geom_line(aes(y = late, color = "late", lty = "late"), size = 1) +
    geom_ribbon(aes(ymin = e_l, ymax = e_u), color = "#CC0000", alpha = 0.05, lty = "dotted") +
    geom_ribbon(aes(ymin = n_l, ymax = n_u), color = "#1B9E77", alpha = 0.05, lty = "dotted") +
    geom_ribbon(aes(ymin = l_l, ymax = l_u), color = "#0000CC", alpha = 0.05, lty = "dotted") +
    theme_minimal() +
    scale_color_manual(values = colors) +
    scale_linetype_manual(values = linetypes) + 
    labs(x = "Grade"
         , y = "Coeduccation Scale"
         , color = "Puberty Group"
         , lty = "Puberty Group") +
    theme(legend.position = "bottom",
          plot.title = element_text(family = "Times", size = (16)),
          legend.title = element_text(family = "Times", size = (16)),
          legend.text = element_text(family = "Times", size = (16)),
          axis.title = element_text(family = "Times", size = (16)),
          axis.text = element_text(family = "Times", size = (16)))
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다

## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## 윈도우즈 폰트데이터베이스에서 찾을 수 없는 폰트페밀리입니다