HW4

Author

Jonathan Ross

Hawaii Precipitation

Using data from https://www.ncei.noaa.gov, precipitation data was collated from 5 weather stations on the islands of Hawaii.

weather <- read.csv('Weather.csv')


library(ggplot2)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(ggdendro)
Warning: package 'ggdendro' was built under R version 4.0.5
library(mapproj)
Warning: package 'mapproj' was built under R version 4.0.5
Loading required package: maps
library(knitr)
#make average prcp per year
weather$year <- substr(weather$DATE, 1,4)
weather$month <- substr(weather$DATE, 6,7)
p <- weather %>%
  group_by(STATION, NAME, year) %>%
  summarise(prcp=mean(PRCP),
            Latitude=mean(LATITUDE), 
            Longitude=mean(LONGITUDE)) 
`summarise()` regrouping output by 'STATION', 'NAME' (override with `.groups` argument)
m <- na.omit(weather) %>%
  group_by(STATION, NAME, month) %>%
  summarise(prcp=mean(PRCP),
            Latitude=mean(LATITUDE), 
            Longitude=mean(LONGITUDE))
`summarise()` regrouping output by 'STATION', 'NAME' (override with `.groups` argument)

Summary Table

The table below shows the average rainfall per month in inches for each of the 5 weather stations. This table helps the reader understand and compare the average monthly rainfall. The average rainfall per month column is color coded to bring to the readers attention. Rainfall in Hilo stands out as different compared to the other weather stations.

library(kableExtra)

Attaching package: 'kableExtra'
The following object is masked from 'package:dplyr':

    group_rows
z<- na.omit(weather)
q <- z %>%
  group_by(NAME) %>%
  summarise(Count = n(), 
            Avg_Prcp=round(mean(PRCP),4),
            SD = round(sd(PRCP),4))
`summarise()` ungrouping output (override with `.groups` argument)
q %>%
  kbl(caption = "Average Monthly Rainfall in Inches") %>%
  kable_paper("hover", full_width = F) %>%
  column_spec(3, color = spec_color(q$Avg_Prcp[1:5], end = 0.5))
Average Monthly Rainfall in Inches
NAME Count Avg_Prcp SD
HILO INTERNATIONAL AIRPORT 87, HI US 875 10.5192 7.5722
HONOLULU INTERNATIONAL AIRPORT, HI US 980 1.6387 2.5044
KAHULUI AIRPORT, HI US 997 1.5007 2.0399
KULA BRANCH STATION 324.5, HI US 515 2.0285 2.2796
LIHUE WEATHER SERVICE OFFICE AIRPORT 1020.1, HI US 871 3.3243 3.3572

This second table shows monthly rain fall data for each of the weather stations. The color gradient was set to easily identify wetter months from dryer months. Wetter months are greener in color while dryer months are purple in color.

library(tidyr)
m <- na.omit(weather)
m.wide <- pivot_wider(m, names_from = month, values_from = PRCP)
m.wide <- m.wide[,-c(1,3:7)]

w <- m.wide %>%
  group_by(NAME) %>%
  summarise(Jan = mean(`01`, na.rm = T), 
            Feb = mean(`02`, na.rm = T),
            Mar = mean(`03`, na.rm = T),
            Apr = mean(`04`, na.rm = T),
            May = mean(`05`, na.rm = T),
            Jun = mean(`06`, na.rm = T),
            Jul = mean(`07`, na.rm = T),
            Aug = mean(`08`, na.rm = T),
            Sep = mean(`09`, na.rm = T),
            Oct = mean(`10`, na.rm = T),
            Nov = mean(`11`, na.rm = T),
            Dec = mean(`12`, na.rm = T),)
`summarise()` ungrouping output (override with `.groups` argument)
w1 <- t(w[2:13])

colnames(w1) <- c("Hilo", "Honolulu", "Kahului", "Kula", "Lihue")

x <-as.numeric( w[1,2:13])
x1 <-as.numeric( w[2,2:13])
x2 <-as.numeric( w[3,2:13])
x3 <-as.numeric( w[4,2:13])
x4 <-as.numeric( w[5,2:13])

w1 %>%
  kbl(caption = "Monthly Rainfall In Inches") %>%
  kable_paper("hover", full_width = F) %>% 
  column_spec(2, color = spec_color(x, end = 0.8)) %>%
  column_spec(3, color = spec_color(x1, end = 0.8)) %>%
  column_spec(4, color = spec_color(x2, end = 0.8)) %>%
  column_spec(5, color = spec_color(x3, end = 0.8)) %>%
  column_spec(6, color = spec_color(x4, end = 0.8)) %>%
  scroll_box(width = "700px", height = "700px") 
Monthly Rainfall In Inches
Hilo Honolulu Kahului Kula Lihue
Jan 8.990548 3.1218293 3.2555422 3.2178571 4.557778
Feb 11.224657 2.2554878 2.2904819 2.9544186 3.608356
Mar 13.088082 2.4892683 2.6310714 3.5304762 4.931781
Apr 12.122740 1.1068293 1.5547561 1.7222727 2.651233
May 8.639863 0.9370732 0.7093976 1.4727273 2.473562
Jun 6.582877 0.4202439 0.2105882 0.8422727 1.614247
Jul 9.409863 0.5144444 0.4576471 0.9466667 1.969726
Aug 10.455890 0.6660494 0.4663529 1.3302326 2.109589
Sep 8.216806 0.7387500 0.3750000 1.3669767 2.234444
Oct 10.100685 1.7576829 0.9746341 1.7909302 3.944722
Nov 14.683425 2.4857317 2.0491463 2.0662791 4.806944
Dec 12.683562 3.1229268 3.1970886 3.2130952 5.043889