-
Notifications
You must be signed in to change notification settings - Fork 1
/
project.Rmd
77 lines (51 loc) · 1.59 KB
/
project.Rmd
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
64
65
66
67
68
69
70
71
72
73
74
75
```{r}
library(scales)
library(tidyverse)
library(modelr)
library(ggplot2)
city <- read_csv(gzfile("data/city_day_agg_cleaned.csv.gz"))
country <- read_csv(gzfile("data/country_day_agg_cleaned.csv.gz"))
```
## plot the world map of NO2,O3, and PM2.5
```{r}
# year_2020<- country %>%
# filter(date > "2019-12-31")
#
# three_year<- country %>%
# filter(date < "2020-01-01")
# separate by parameter
year_2020_pm25 <- year_2020 %>%
filter(parameter =="pm25") %>%
group_by(countryCode) %>%
summarize(avg = mean(mean,na.rm = TRUE))
three_yr_pm25 <- three_year %>%
filter(parameter =="pm25") %>%
group_by(countryCode) %>%
summarize(avg = mean(mean,na.rm = TRUE))
year_2020_pm25_by_city <- city %>%
filter(date > as.Date("2019-12-31")) %>%
filter(parameter == "pm25") %>%
mutate(year = date) %>%
group_by(city_id, date) %>%
summarize(avg = mean(mean, na.rm = TRUE))
three_year_pm25_by_city <- city %>%
filter(date < "2020-01-01") %>%
filter(parameter =="pm25") %>%
group_by(city_id) %>%
summarize(avg = mean(mean,na.rm = TRUE))
# use the is_2020_factor to plot two
pm25 <- inner_join(year_2020_pm25_by_city, three_year_pm25_by_city, by = 'city_id')
# then use the factor for plotting two plots
ggplot(year_2020_pm25_by_city, aes(x = avg), fill = "pink") +
geom_density(fill = is_2020) +
scale_x_log10(label = comma) +
xlab('PM2.5') +
ylab('Data Density')
world <- map_data("world")
ggplot() +
geom_map(
data = world, map = world,
aes(long, lat, map_id = region),
color = "black", fill = "grey", size = 0.1
) +
```