forked from maelle/usaqmindia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redo_plot.R
38 lines (36 loc) · 1.55 KB
/
redo_plot.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
#' Re-do the time series plot for all cities
#'
#' @import ggplot2
#' @import viridis
#'
#' @return a ggplot graph
#' @export
#'
#' @details For clarity a few values of 2000 are not shown for Delhi and Hyderabad.
#'
#' @examples
#' usaqmindia_plot()
usaqmindia_plot <- function(){
utils::data("pm25_india", package = "usaqmindia", envir = environment())
p <- ggplot(dplyr::filter_(pm25_india,
lazyeval::interp(~conc < 1500))) +
geom_vline(xintercept = as.numeric(lubridate::ymd_hms("2013 11 03 20 00 00",
tz = "Asia/Kolkata"))) +
geom_vline(xintercept = as.numeric(lubridate::ymd_hms("2014 10 23 20 00 00",
tz = "Asia/Kolkata"))) +
geom_vline(xintercept = as.numeric(lubridate::ymd_hms("2015 11 11 20 00 00",
tz = "Asia/Kolkata"))) +
geom_point(aes_string("datetime", "conc", col = "city")) +
facet_grid(city ~ .) +
ggtitle("US Air Quality Monitoring in India",
subtitle = "The vertical lines represent 8pm on Diwali each year.")+
ylab(expression(paste("PM2.5 hourly concentration (", mu, "g/",m^3,")")))+
scale_x_datetime(date_labels = "%Y-%b-%d",
date_breaks = "2 month")+
theme(axis.text.x = element_text(angle = 45, hjust = 1))+
theme(strip.text.y = element_text(size = 16, angle = 0)) +
scale_color_viridis(discrete = TRUE)+
theme(legend.position = "none")+
xlab("Local time")
p
}