Randomly Sampled Global Summary of the Month Climatology data from 10
stations
10 Stations across 10 States (5 from West and 5 from East)
West: California, Nevada, Idaho, Oregon, Washington
East: Connecticut, Massachusetts, North Carolina, New Jersey,
Virginia
Precipitation is higher in the east sides compared with the west
sides
The variance of precipitation in the east side is much smaller
The Temperature is keep increasing in both east and west sides
East side has relatively higher temperature compared with the west
side
The east side has heavier snowfall compared with the east side
OR has the narrowest gap between highest and the lowest
temperature
NV has the broadest gap between the highest and the lowest
temperature
---
title: "ANLY512 - Lab2"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(quantmod)
library(plyr)
library(ggplot2)
library(maps)
library(dplyr)
library(ggalt)
gsom <- read.csv("gsom.csv")
cleanup <- theme(panel.grid.major = element_blank(), #no grid lines
panel.grid.minor = element_blank(), #no grid lines
panel.background = element_blank(), #no background
axis.line.x = element_line(color = 'black'), #black x axis line
axis.line.y = element_line(color = 'black'), #black y axis line
legend.key = element_rect(fill = 'white'), #no legend background
text = element_text(size = 15)) #bigger text size
```
## Stations Map {.storyboard data-orientation=rows data-icon="fa_list"}
### Data Sampling {data-height=150}
Randomly Sampled Global Summary of the Month Climatology data from 10 stations\
10 Stations across 10 States (5 from West and 5 from East)\
West: California, Nevada, Idaho, Oregon, Washington \
East: Connecticut, Massachusetts, North Carolina, New Jersey, Virginia\
\
### Stations Map {data-height=500}
```{r message=FALSE}
all_states <- map_data("state")
west <- all_states[all_states$region %in% c("california", "nevada", "idaho",
"oregon", "washington"), ]
east <- all_states[all_states$region %in% c("connecticut", "massachusetts", "north carolina",
"new jersey", "virginia"), ]
ggplot()+ geom_polygon(data=all_states,
aes(x=long, y=lat, group = group),
colour="black", fill="#eeeeee")+
geom_polygon(data = west,
aes(x=long, y=lat, group = group),
colour="black", fill="#7ff9e9")+
geom_polygon(data = east, aes(x=long, y=lat, group = group),
colour="black", fill="#fbb1b5")+
theme_void()+
cleanup
```
## Analysis {.tabset .tabset-fade}
### Precipitation {.storyboard data-orientation=rows data-icon="fa_list"}
#### Idea1 {data-height=150}
Precipitation is higher in the east sides compared with the west sides \
The variance of precipitation in the east side is much smaller \
\
#### Visulization {data-height=500}
```{r message=FALSE}
gsom$State <-factor(gsom$State, levels=c("CA", "ID", "NV", "OR", "WA",
"CT", "MA", "NC", "NJ", "VA"))
p <- ggplot(gsom, aes(x=reorder(State, Division), y=PRCP, colour = Division)) +
geom_jitter(width = 0.2, alpha = 0.25)+
geom_boxplot(alpha = 0.25, coef = 2.5)+
labs(x="State", y="Total Monthly Precipitation (inches)",
subtitle="Total Monthly Precipitation Box Plot across States")+
cleanup
p
```
### Temperature {.storyboard data-orientation=rows data-icon="fa_list"}
#### Idea2: {data-height=150}
The Temperature is keep increasing in both east and west sides\
East side has relatively higher temperature compared with the west side \
#### Visualization {data-height=150}
```{r message=FALSE}
gsom$DATE <- as.Date(paste0(gsom$DATE, '-01'), format="%Y-%m-%d")
gsom$YEAR <- format(gsom$DATE, "%Y")
gsom$YEAR <- as.Date(paste0(gsom$YEAR, '-01-01'), format="%Y-%m-%d")
gsom_year <- gsom %>% group_by(YEAR, Division) %>%
summarise(mean_temp=mean(TAVG, na.rm=TRUE))
P <- ggplot(gsom_year,
aes(x=gsom_year$YEAR, y=mean_temp, group=Division,
colour=Division))+
geom_line(size=0.7)+
geom_point()+
labs(x="Year", y="Yearly Average Temperature (Celsius)",
subtitle="Average Temperature Time Series across Divisions")+
cleanup
P
```
### Snowfall {.storyboard data-orientation=rows data-icon="fa_list"}
#### Idea3: {data-height=150}
The east side has heavier snowfall compared with the east side \
\
#### Visualization {data-height=500}
```{r message=FALSE}
gsom_snow_year <- gsom %>% group_by(YEAR, Division) %>%
summarise(tot_snow=sum(SNOW, na.rm=TRUE))
ggplot(gsom_snow_year,
aes(tot_snow, group=Division, fill=Division))+
geom_density(stat = "density", alpha=0.5)+
labs(x="Yearly Snowfall(inches)", y="Density",
subtitle="Yearly Snowfall Density across Divisions")+
cleanup
```
### Temperature Gap {.storyboard data-orientation=rows data-icon="fa_list"}
#### Idea4 {data-height=150}
OR has the narrowest gap between highest and the lowest temperature \
NV has the broadest gap between the highest and the lowest temperature \
\
#### Visualization {data-height=500}
```{r message=FALSE}
gsom_state_diff <- gsom[as.character(format(gsom$YEAR,'%Y'))=="2021", ] %>%
group_by(State) %>%
summarise(TMAX=max(TMAX, na.rm=TRUE),
TMIN=min(TMIN, na.rm=TRUE))
gsom_state_diff$diff <- gsom_state_diff$TMAX - gsom_state_diff$TMIN
p <- ggplot()+
# doing this vs y axis major grid line
geom_segment(data=gsom_state_diff,
aes(y=State, yend=State, x=-10, xend=40),
color="#b2b2b2", size=0.15)+
geom_dumbbell(data=gsom_state_diff,
aes(y=State, x=TMIN, xend=TMAX),
size=1.5, color="#b2b2b2",
point.size.l=3, point.size.r=3,
point.colour.l="#9fb059", point.colour.r="#edae52")+
geom_text(data=filter(gsom_state_diff, State=="VA"),
aes(x=TMIN, y=State, label="Min Temperature"),
color="#9fb059", size=3, vjust=-2,
fontface="bold", family="Calibri")+
geom_text(data=filter(gsom_state_diff, State=="VA"),
aes(x=TMAX, y=State, label="Max Temperature"),
color="#edae52", size=3, vjust=-2,
fontface="bold", family="Calibri")+
geom_text(data=gsom_state_diff,
aes(x=TMIN, y=State, label=TMIN),
color="#9fb059", size=2.75,
vjust=2.5, family="Calibri")+
geom_text(data=gsom_state_diff,
color="#edae52", size=2.75, vjust=2.5, family="Calibri",
aes(x=TMAX, y=State, label=TMAX))+
geom_rect(data=gsom_state_diff,
aes(xmin=42.05, xmax=42.175, ymin=-Inf, ymax=Inf),
fill="#efefe3")+
geom_text(data=gsom_state_diff,
aes(label=diff, y=State, x=42.1125),
fontface="bold", size=3, family="Calibri")+
geom_text(data=filter(gsom_state_diff, State=="VA"),
aes(x=42.1125, y=State, label="DIFF"),
color="#7a7d7e", size=3.1, vjust=-2,
fontface="bold", family="Calibri")+
scale_x_continuous(expand=c(0.075,0))+
scale_y_discrete(expand=c(0.1,0))+
labs(x=NULL, title="The 2021 Temperature across 10 States")+
theme_bw(base_family="Calibri")+
theme(panel.grid.major=element_blank())+
theme(panel.grid.minor=element_blank())+
theme(panel.border=element_blank())+
theme(axis.ticks=element_blank())+
theme(axis.text.x=element_blank())+
theme(plot.title=element_text(face="bold"))+
theme(plot.subtitle=element_text(face="italic",
size=9, margin=margin(b=12)))+
theme(plot.caption=element_text(size=7, margin=margin(t=12),
color="#7a7d7e"))
p
```