-
Notifications
You must be signed in to change notification settings - Fork 1
/
Figure5_PM2.5.R
63 lines (39 loc) · 1.76 KB
/
Figure5_PM2.5.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
### Code to plot PM2.5 mean difference of PE for the years 2019 and 2020
library(readxl)
library(tidyverse)
library(boot)
library(ggthemes)
library(grid)
library(gridExtra)
library(forecast)
library(data.table)
library(cowplot)
df_all_plot_pm25 <- read.csv('df_box_PM25_2019_2020_Jan_Apr.csv')
df_all_plot_pm25$Year = factor(df_all_plot_pm25$Year)
state.abb = as.character(unique(df_all_plot_pm25$state))
df_pm25_summary <- df_all_plot_pm25 %>% group_by(state,Year) %>% summarise(pm25 = mean(mean_diff))
df_pm25_summary$Year = factor(df_pm25_summary$Year)
df_pm25_2019 = subset(df_pm25_summary, Year == "2019")
df_pm25_2020 = subset(df_pm25_summary, Year == "2020")
colors <- c("2019" = "red",
"2020" = "blue")
df_pm25_summary.2 = data.frame(df_pm25_summary)
df_pm25_summary.2$Year = as.numeric(as.character(df_pm25_summary.2$Year))
df_wide_pm25 <- reshape(df_pm25_summary.2, direction = "wide", v.names="pm25", timevar="Year", idvar="state")
png("figures/PM25_2019_2020_mean_difference.png", height = 1000, width=1500)
pm.plot <- ggplot(df_pm25_summary, aes(x=state, y=pm25, colour=Year)) +
geom_point(size=5)+
geom_hline(yintercept = 0)+
geom_segment(aes(x=state, xend=state, y=pm25.2019, yend=pm25.2020),
size=1, data=df_wide_pm25, colour="black", linetype="dotted")+
theme_classic()+
theme(plot.title = element_text(hjust = 0.5))+
theme(axis.text.x = element_text(size = 14, angle = 45),
axis.text.y = element_text(size = 14),
axis.title = element_text(size = 16),
legend.title = element_text(size=14), #change legend title font size
legend.text = element_text(size=14))+
xlab("State")+
ylab("PM2.5 mean difference")
pm.plot
dev.off()