# setwd("path/to/Norpred")  # 已注释：请按本地环境设置工作目录
DASIR <-  read.csv('1\\depression\\incidence\\inyouthASR_data.csv')
DASPR <-  read.csv('1\\depression\\prevalence\\PyouthASR_data.csv')
DASDR <-  read.csv('1\\depression\\DALYS\\inDYyouthASR_data.csv')
library(ggplot2)
library(dplyr)

# 定义高级的绿色色调
color_female <- "#66CDAA" # MediumAquamarine
color_male <- "#8FBC8F" # DarkSeaGreen

# 分割数据：2022年之前、2021-2022和2022年之后的数据
DASIR_before_2022 <- DASIR %>% filter(year < 2022 & sex %in% c("Female", "Male"))
DASIR_2021_2022 <- DASIR %>% filter(year %in% c(2021, 2022) & sex %in% c("Female", "Male"))
DASIR_after_2022 <- DASIR %>% filter(year > 2022 & sex %in% c("Female", "Male"))

# 绘制DASIR图表并保存到对象p1中
p1 <- ggplot() +
  geom_line(data = DASIR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "solid") +
  geom_line(data = DASIR_2021_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_line(data = DASIR_after_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_point(data = DASIR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  geom_point(data = DASIR_2021_2022 %>% filter(year == 2021), aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  labs(title = "the ASIR of Depressive disorders",
       x = "Year",
       y = "ASIR (per 100,000)") +
  theme_minimal(base_family = "Arial") +
  theme(panel.background = element_rect(fill = "white", color = "black"),
        plot.background = element_rect(fill = "white", color = "black"),
        panel.border = element_rect(color = "black", fill = NA, size = 1)) +
  scale_color_manual(values = c("Female" = color_female, "Male" = color_male)) +
  scale_y_continuous(breaks = seq(0, max(DASIR$ASR, na.rm = TRUE), by = 200)) + # 设置纵坐标刻度
  scale_x_continuous(breaks = seq(min(DASIR$year, na.rm = TRUE), max(DASIR$year, na.rm = TRUE), by = 5)) + # 设置横坐标刻度
  geom_vline(xintercept = 2021, linetype = "dashed", color = "grey", size = 1) # 添加2021年的虚线

# 分割数据：2022年之前、2021-2022和2022年之后的数据
DASPR_before_2022 <- DASPR %>% filter(year < 2022 & sex %in% c("Female", "Male"))
DASPR_2021_2022 <- DASPR %>% filter(year %in% c(2021, 2022) & sex %in% c("Female", "Male"))
DASPR_after_2022 <- DASPR %>% filter(year > 2022 & sex %in% c("Female", "Male"))

# 绘制DASPR图表并保存到对象p2中
p2 <- ggplot() +
  geom_line(data = DASPR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "solid") +
  geom_line(data = DASPR_2021_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_line(data = DASPR_after_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_point(data = DASPR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  geom_point(data = DASPR_2021_2022 %>% filter(year == 2021), aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  labs(title = "the ASPR of Depressive disorders",
       x = "Year",
       y = "ASPR (per 100,000)") +
  theme_minimal(base_family = "Arial") +
  theme(panel.background = element_rect(fill = "white", color = "black"),
        plot.background = element_rect(fill = "white", color = "black"),
        panel.border = element_rect(color = "black", fill = NA, size = 1)) +
  scale_color_manual(values = c("Female" = color_female, "Male" = color_male)) +
  scale_y_continuous(breaks = seq(0, max(DASPR$ASR, na.rm = TRUE), by = 200)) + # 设置纵坐标刻度
  scale_x_continuous(breaks = seq(min(DASPR$year, na.rm = TRUE), max(DASPR$year, na.rm = TRUE), by = 5)) + # 设置横坐标刻度
  geom_vline(xintercept = 2021, linetype = "dashed", color = "grey", size = 1) # 添加2021年的虚线

# 分割数据：2022年之前、2021-2022和2022年之后的数据
DASDR_before_2022 <- DASDR %>% filter(year < 2022 & sex %in% c("Female", "Male"))
DASDR_2021_2022 <- DASDR %>% filter(year %in% c(2021, 2022) & sex %in% c("Female", "Male"))
DASDR_after_2022 <- DASDR %>% filter(year > 2022 & sex %in% c("Female", "Male"))

# 绘制DASDR图表并保存到对象p3中
p3 <- ggplot() +
  geom_line(data = DASDR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "solid") +
  geom_line(data = DASDR_2021_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_line(data = DASDR_after_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_point(data = DASDR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  geom_point(data = DASDR_2021_2022 %>% filter(year == 2021), aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  labs(title = "the ASDR of Depressive disorders",
       x = "Year",
       y = "ASDR (per 100,000)") +
  theme_minimal(base_family = "Arial") +
  theme(panel.background = element_rect(fill = "white", color = "black"),
        plot.background = element_rect(fill = "white", color = "black"),
        panel.border = element_rect(color = "black", fill = NA, size = 1)) +
  scale_color_manual(values = c("Female" = color_female, "Male" = color_male)) +
  scale_y_continuous(breaks = seq(0, max(DASDR$ASR, na.rm = TRUE), by = 200)) + # 设置纵坐标刻度
  scale_x_continuous(breaks = seq(min(DASDR$year, na.rm = TRUE), max(DASDR$year, na.rm = TRUE), by = 5)) + # 设置横坐标刻度
  geom_vline(xintercept = 2021, linetype = "dashed", color = "grey", size = 1) # 添加2021年的虚线

# 将三个图放在一行三列中
# 加载所需的库
library(gridExtra)

# 将三个图放在一行三列中
p <- grid.arrange(p1, p2, p3, ncol = 3)

# 保存图像
ggsave("1/Depressive-disorders.png", plot = p, width = 20, height = 5, dpi = 300)


# setwd("path/to/Norpred")  # 已注释：请按本地环境设置工作目录
DASIR <-  read.csv('1\\Dysthymia\\incidence\\inDYyouthASR_data.csv')
DASPR <-  read.csv('1\\Dysthymia\\prevalence\\PDYyouthASR_data.csv')
DASDR <-  read.csv('1\\Dysthymia\\DALYS\\DALYDYyouthASR_data.csv')
library(ggplot2)
library(dplyr)

# 定义高级的绿色色调
color_female <- "#66CDAA" # MediumAquamarine
color_male <- "#8FBC8F" # DarkSeaGreen

# 分割数据：2022年之前、2021-2022和2022年之后的数据
DASIR_before_2022 <- DASIR %>% filter(year < 2022 & sex %in% c("Female", "Male"))
DASIR_2021_2022 <- DASIR %>% filter(year %in% c(2021, 2022) & sex %in% c("Female", "Male"))
DASIR_after_2022 <- DASIR %>% filter(year > 2022 & sex %in% c("Female", "Male"))

# 绘制DASIR图表并保存到对象p1中
p1 <- ggplot() +
  geom_line(data = DASIR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "solid") +
  geom_line(data = DASIR_2021_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_line(data = DASIR_after_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_point(data = DASIR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  geom_point(data = DASIR_2021_2022 %>% filter(year == 2021), aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  labs(title = "the ASIR of Dysthymia",
       x = "Year",
       y = "ASIR (per 100,000)") +
  theme_minimal(base_family = "Arial") +
  theme(panel.background = element_rect(fill = "white", color = "black"),
        plot.background = element_rect(fill = "white", color = "black"),
        panel.border = element_rect(color = "black", fill = NA, size = 1)) +
  scale_color_manual(values = c("Female" = color_female, "Male" = color_male)) +
  scale_y_continuous(breaks = seq(0, max(DASIR$ASR, na.rm = TRUE), by = 200)) + # 设置纵坐标刻度
  scale_x_continuous(breaks = seq(min(DASIR$year, na.rm = TRUE), max(DASIR$year, na.rm = TRUE), by = 5)) + # 设置横坐标刻度
  geom_vline(xintercept = 2021, linetype = "dashed", color = "grey", size = 1) # 添加2021年的虚线

# 分割数据：2022年之前、2021-2022和2022年之后的数据
DASPR_before_2022 <- DASPR %>% filter(year < 2022 & sex %in% c("Female", "Male"))
DASPR_2021_2022 <- DASPR %>% filter(year %in% c(2021, 2022) & sex %in% c("Female", "Male"))
DASPR_after_2022 <- DASPR %>% filter(year > 2022 & sex %in% c("Female", "Male"))

# 绘制DASPR图表并保存到对象p2中
p2 <- ggplot() +
  geom_line(data = DASPR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "solid") +
  geom_line(data = DASPR_2021_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_line(data = DASPR_after_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_point(data = DASPR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  geom_point(data = DASPR_2021_2022 %>% filter(year == 2021), aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  labs(title = "the ASPR of Dysthymia",
       x = "Year",
       y = "ASPR (per 100,000)") +
  theme_minimal(base_family = "Arial") +
  theme(panel.background = element_rect(fill = "white", color = "black"),
        plot.background = element_rect(fill = "white", color = "black"),
        panel.border = element_rect(color = "black", fill = NA, size = 1)) +
  scale_color_manual(values = c("Female" = color_female, "Male" = color_male)) +
  scale_y_continuous(breaks = seq(0, max(DASPR$ASR, na.rm = TRUE), by = 200)) + # 设置纵坐标刻度
  scale_x_continuous(breaks = seq(min(DASPR$year, na.rm = TRUE), max(DASPR$year, na.rm = TRUE), by = 5)) + # 设置横坐标刻度
  geom_vline(xintercept = 2021, linetype = "dashed", color = "grey", size = 1) # 添加2021年的虚线

# 分割数据：2022年之前、2021-2022和2022年之后的数据
DASDR_before_2022 <- DASDR %>% filter(year < 2022 & sex %in% c("Female", "Male"))
DASDR_2021_2022 <- DASDR %>% filter(year %in% c(2021, 2022) & sex %in% c("Female", "Male"))
DASDR_after_2022 <- DASDR %>% filter(year > 2022 & sex %in% c("Female", "Male"))

# 绘制DASDR图表并保存到对象p3中
p3 <- ggplot() +
  geom_line(data = DASDR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "solid") +
  geom_line(data = DASDR_2021_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_line(data = DASDR_after_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_point(data = DASDR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  geom_point(data = DASDR_2021_2022 %>% filter(year == 2021), aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  labs(title = "the ASDR of Dysthymia",
       x = "Year",
       y = "ASDR (per 100,000)") +
  theme_minimal(base_family = "Arial") +
  theme(panel.background = element_rect(fill = "white", color = "black"),
        plot.background = element_rect(fill = "white", color = "black"),
        panel.border = element_rect(color = "black", fill = NA, size = 1)) +
  scale_color_manual(values = c("Female" = color_female, "Male" = color_male)) +
  scale_y_continuous(breaks = seq(0, max(DASDR$ASR, na.rm = TRUE), by = 200)) + # 设置纵坐标刻度
  scale_x_continuous(breaks = seq(min(DASDR$year, na.rm = TRUE), max(DASDR$year, na.rm = TRUE), by = 5)) + # 设置横坐标刻度
  geom_vline(xintercept = 2021, linetype = "dashed", color = "grey", size = 1) # 添加2021年的虚线

# 将三个图放在一行三列中
# 加载所需的库
library(gridExtra)

# 将三个图放在一行三列中
p <- grid.arrange(p1, p2, p3, ncol = 3)

# 保存图像
ggsave("1/Dysthymia.png", plot = p, width = 20, height = 5, dpi = 300)




# setwd("path/to/Norpred")  # 已注释：请按本地环境设置工作目录

DASIR <-  read.csv('1\\Major-depressive-disorder\\incidence\\inMAyouthASR_data.csv')
DASPR <-  read.csv('1\\Major-depressive-disorder\\prevalence\\PMAyouthASR_data.csv')
DASDR <-  read.csv('1\\Major-depressive-disorder\\DALYS\\DALYMAyouthASR_data.csv')
library(ggplot2)
library(dplyr)

# 定义高级的绿色色调
color_female <- "#66CDAA" # MediumAquamarine
color_male <- "#8FBC8F" # DarkSeaGreen

# 分割数据：2022年之前、2021-2022和2022年之后的数据
DASIR_before_2022 <- DASIR %>% filter(year < 2022 & sex %in% c("Female", "Male"))
DASIR_2021_2022 <- DASIR %>% filter(year %in% c(2021, 2022) & sex %in% c("Female", "Male"))
DASIR_after_2022 <- DASIR %>% filter(year > 2022 & sex %in% c("Female", "Male"))

# 绘制DASIR图表并保存到对象p1中
p1 <- ggplot() +
  geom_line(data = DASIR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "solid") +
  geom_line(data = DASIR_2021_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_line(data = DASIR_after_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_point(data = DASIR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  geom_point(data = DASIR_2021_2022 %>% filter(year == 2021), aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  labs(title = "the ASIR of Major depressive disorder",
       x = "Year",
       y = "ASIR (per 100,000)") +
  theme_minimal(base_family = "Arial") +
  theme(panel.background = element_rect(fill = "white", color = "black"),
        plot.background = element_rect(fill = "white", color = "black"),
        panel.border = element_rect(color = "black", fill = NA, size = 1)) +
  scale_color_manual(values = c("Female" = color_female, "Male" = color_male)) +
  scale_y_continuous(breaks = seq(0, max(DASIR$ASR, na.rm = TRUE), by = 200)) + # 设置纵坐标刻度
  scale_x_continuous(breaks = seq(min(DASIR$year, na.rm = TRUE), max(DASIR$year, na.rm = TRUE), by = 5)) + # 设置横坐标刻度
  geom_vline(xintercept = 2021, linetype = "dashed", color = "grey", size = 1) # 添加2021年的虚线

# 分割数据：2022年之前、2021-2022和2022年之后的数据
DASPR_before_2022 <- DASPR %>% filter(year < 2022 & sex %in% c("Female", "Male"))
DASPR_2021_2022 <- DASPR %>% filter(year %in% c(2021, 2022) & sex %in% c("Female", "Male"))
DASPR_after_2022 <- DASPR %>% filter(year > 2022 & sex %in% c("Female", "Male"))

# 绘制DASPR图表并保存到对象p2中
p2 <- ggplot() +
  geom_line(data = DASPR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "solid") +
  geom_line(data = DASPR_2021_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_line(data = DASPR_after_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_point(data = DASPR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  geom_point(data = DASPR_2021_2022 %>% filter(year == 2021), aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  labs(title = "the ASPR of Major depressive disorder",
       x = "Year",
       y = "ASPR (per 100,000)") +
  theme_minimal(base_family = "Arial") +
  theme(panel.background = element_rect(fill = "white", color = "black"),
        plot.background = element_rect(fill = "white", color = "black"),
        panel.border = element_rect(color = "black", fill = NA, size = 1)) +
  scale_color_manual(values = c("Female" = color_female, "Male" = color_male)) +
  scale_y_continuous(breaks = seq(0, max(DASPR$ASR, na.rm = TRUE), by = 200)) + # 设置纵坐标刻度
  scale_x_continuous(breaks = seq(min(DASPR$year, na.rm = TRUE), max(DASPR$year, na.rm = TRUE), by = 5)) + # 设置横坐标刻度
  geom_vline(xintercept = 2021, linetype = "dashed", color = "grey", size = 1) # 添加2021年的虚线

# 分割数据：2022年之前、2021-2022和2022年之后的数据
DASDR_before_2022 <- DASDR %>% filter(year < 2022 & sex %in% c("Female", "Male"))
DASDR_2021_2022 <- DASDR %>% filter(year %in% c(2021, 2022) & sex %in% c("Female", "Male"))
DASDR_after_2022 <- DASDR %>% filter(year > 2022 & sex %in% c("Female", "Male"))

# 绘制DASDR图表并保存到对象p3中
p3 <- ggplot() +
  geom_line(data = DASDR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "solid") +
  geom_line(data = DASDR_2021_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_line(data = DASDR_after_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_point(data = DASDR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  geom_point(data = DASDR_2021_2022 %>% filter(year == 2021), aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  labs(title = "the ASDR of Major depressive disorder",
       x = "Year",
       y = "ASDR (per 100,000)") +
  theme_minimal(base_family = "Arial") +
  theme(panel.background = element_rect(fill = "white", color = "black"),
        plot.background = element_rect(fill = "white", color = "black"),
        panel.border = element_rect(color = "black", fill = NA, size = 1)) +
  scale_color_manual(values = c("Female" = color_female, "Male" = color_male)) +
  scale_y_continuous(breaks = seq(0, max(DASDR$ASR, na.rm = TRUE), by = 200)) + # 设置纵坐标刻度
  scale_x_continuous(breaks = seq(min(DASDR$year, na.rm = TRUE), max(DASDR$year, na.rm = TRUE), by = 5)) + # 设置横坐标刻度
  geom_vline(xintercept = 2021, linetype = "dashed", color = "grey", size = 1) # 添加2021年的虚线

# 将三个图放在一行三列中
# 加载所需的库
library(gridExtra)

# 将三个图放在一行三列中
p <- grid.arrange(p1, p2, p3, ncol = 3)

# 保存图像
ggsave("1/Major-depressive-disorder.png", plot = p, width = 20, height = 5, dpi = 300)

#############绘制柱状图和折线图##################
# setwd("path/to/Norpred")  # 已注释：请按本地环境设置工作目录
data <-  read.csv('1\\ASR.csv')
DASIR <- subset(data, measure == 'Incidence' & cause == 'Depressive disorders')
data1 <-  read.csv('1\\depression\\incidence\\inyouthNum_data.csv')
library(ggplot2)
library(dplyr)

# 定义高级的绿色色调
color_female <- "#66CDAA" # MediumAquamarine
color_male <- "#8FBC8F" # DarkSeaGreen
color_both <- "#32CD32" # LimeGreen

# 过滤数据，保留1990-2021年，并且性别为Female, Male或Both的数据
DASIR_1990_2021 <- DASIR %>% filter(year >= 1990 & year <= 2021 & sex %in% c("Female", "Male", "Both"))
data1_1990_2021 <- data1 %>% filter(year >= 1990 & year <= 2021 & sex %in% c("Female", "Male", "Both"))


# 确保两个数据集的y轴范围适合显示
max_asr <- max(DASIR_1990_2021$ASR, na.rm = TRUE)
max_num <- max(data1_1990_2021$number, na.rm = TRUE)

# 绘制DASIR图表并保存到对象p1中
p1 <- ggplot() +
  geom_bar(data = data1_1990_2021, aes(x = year, y = number, fill = sex), stat = "identity", position = "dodge", alpha = 0.6) +
  geom_line(data = DASIR_1990_2021, aes(x = year, y = ASR * (max_num / max_asr), color = sex, group = sex), size = 1.2, linetype = "solid") +
  geom_point(data = DASIR_1990_2021, aes(x = year, y = ASR * (max_num / max_asr), color = sex, group = sex), size = 2) +
  labs(title = "Depressive disorders",
       x = "Year",
       y = "Number of cases",
       fill = "Sex",
       color = "Sex") +
  theme_minimal(base_family = "Arial") +
  theme(panel.background = element_rect(fill = "white", color = "black"),
        plot.background = element_rect(fill = "white", color = "black"),
        panel.border = element_rect(color = "black", fill = NA, size = 1)) +
  scale_color_manual(values = c("Female" = color_female, "Male" = color_male, "Both" = color_both)) +
  scale_fill_manual(values = c("Female" = color_female, "Male" = color_male, "Both" = color_both)) +
  scale_y_continuous(name = "Number of cases", 
                     sec.axis = sec_axis(~ . * (max_asr / max_num), name = "ASIR (per 100,000)")) + # 设置次坐标轴
  scale_x_continuous(breaks = seq(1990, 2021, by = 5)) # 设置横坐标刻度为每年一个标记

# 显示图表
print(p1)
ggsave("1/抑郁症ASIR.png", plot = p1, width = 8, height = 5, dpi = 300)







##############################################绘制柱状图###################################
# 读取数据
innum_data <- read.csv('1\\depression\\incidence\\inyouthNum_data.csv')
# setwd("path/to/Norpred")  # 已注释：请按本地环境设置工作目录
DASIR <-  read.csv('1\\depression\\incidence\\inyouthASR_data.csv')
DASPR <-  read.csv('1\\depression\\prevalence\\PyouthASR_data.csv')
DASDR <-  read.csv('1\\depression\\DALYS\\inDYyouthASR_data.csv')
# 加载必要的库
library(ggplot2)

# 绘制柱状图
p2 <- ggplot(innum_data, aes(x = year, y = number, fill = sex)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(title = "Number of Cases by Year and Sex",
       x = "Year",
       y = "Number of Cases",
       fill = "Sex") +
  theme_minimal(base_family = "Arial") +
  theme(panel.background = element_rect(fill = "white", color = "black"),
        plot.background = element_rect(fill = "white", color = "black"),
        panel.border = element_rect(color = "black", fill = NA, size = 1)) +
  scale_fill_manual(values = c("Female" = "#66CDAA", "Male" = "#8FBC8F"))

# 显示图表
print(p2)
ggsave("1/1.png", plot = p2, width = 8, height = 5, dpi = 300)





# 保存图形到文件
ggsave("1\\20-44_Prevalence_青年抑郁症.png", plot = p, width = 10, height = 6, dpi = 300)


##########绘制置信区间###############
library(ggplot2)
library(dplyr)

# 定义高级的绿色色调
color_female <- "#66CDAA" # MediumAquamarine

# 加载数据
ASR <- read.csv("1\\PyouthASR区间_data.csv")

# 确保 ASR 列为数值类型
ASR$ASR <- as.numeric(ASR$ASR)
ASR$lower <- as.numeric(ASR$lower)
ASR$upper <- as.numeric(ASR$upper)

# 分割数据：2022年之前、2021-2022和2022年之后的数据
ASR_before_2022 <- ASR %>% filter(year < 2022 & sex == "Female")
ASR_2021_2022 <- ASR %>% filter(year %in% c(2021, 2022) & sex == "Female")
ASR_after_2022 <- ASR %>% filter(year > 2022 & sex == "Female")

# 绘制ASR图表并保存到对象p中
p <- ggplot() +
  geom_line(data = ASR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "solid") +
  geom_line(data = ASR_2021_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_line(data = ASR_after_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 1.2, linetype = "dashed") +
  geom_point(data = ASR_before_2022, aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  geom_point(data = ASR_2021_2022 %>% filter(year == 2021), aes(x = year, y = ASR, color = sex, group = sex), size = 2) +
  geom_ribbon(data = ASR_after_2022, aes(x = year, ymin = lower, ymax = upper, fill = sex), alpha = 0.2) + # 添加预测区间阴影
  labs(title = "the ASR of Depressive disorders (Female)",
       x = "Year",
       y = "ASR (per 100,000)") +
  theme_minimal(base_family = "Arial") +
  theme(panel.background = element_rect(fill = "white", color = "black"),
        plot.background = element_rect(fill = "white", color = "black"),
        panel.border = element_rect(color = "black", fill = NA, size = 1)) +
  scale_color_manual(values = c("Female" = color_female)) +
  scale_fill_manual(values = c("Female" = color_female)) +
  scale_y_continuous(breaks = seq(0, max(ASR$ASR, na.rm = TRUE), by = 200)) + # 设置纵坐标刻度
  scale_x_continuous(breaks = seq(min(ASR$year, na.rm = TRUE), max(ASR$year, na.rm = TRUE), by = 5)) + # 设置横坐标刻度
  geom_vline(xintercept = 2021, linetype = "dashed", color = "grey", size = 1) # 添加2021年的虚线

# 保存图形到文件
ggsave("1/20-44_Prevalence_女青年抑郁症.png", plot = p, width = 10, height = 6, dpi = 300)









