Question 1

Based on skills you have already developed, acquire hourly weather data for at least five different cities with contrasting climatic conditions, such as a couple of cities from the coastal areas, a couple of cities from the middle parts of the US, a couple from the northern parts near the Great Lakes, and a couple from Southern parts.

library(readr)
library(tidyverse)
alpena_mi <- read_csv("alpena.mi.csv")
burns_or <- read_csv("burns.or.csv")
louisville_ky <- read_csv("louisville.ky.csv")
lufkin_tx <- read_csv("lufkin.tx.csv")
worcester_ma <- read_csv("worcester.ma.csv")
fivestat<-rbind(alpena_mi,burns_or,louisville_ky,lufkin_tx,worcester_ma) #compiling the datasets into one

library(maps)
map("world", regions=c("usa"), fill=T, col="dark green", bg="light blue", ylim=c(21.0,50.0), xlim=c(-130.0,-65.0))
points(fivestat$LONGITUDE,fivestat$LATITUDE, pch=2, cex=1, col="white")
title("Map of Cities Used for Analysis")

Question 2

Provide descriptive analyses of temperature and relative humidity of both cities (4 points), and create line graphs of daily temperature and relative humidity, presenting them all in the same graph and provide a description of these two meteorological conditions and their associated health implications (4 points).

Alpena, MI Data

alpena_mi <- #both the DewPoint and Temp data are in Degrees F without the decimal for the tenths place
alpena_mi <- mutate(alpena_mi, TempF=HourlyTemp/10)
alpena_mi <- mutate(alpena_mi, TempC=(5/9)*(TempF - 32))

alpena_mi <- mutate(alpena_mi, DewPointF=HourlyDewPoint/10)
alpena_mi <- mutate(alpena_mi, DewPointC=(5/9)*(DewPointF - 32))
alpena_mi <- na.omit(alpena_mi)

#need to create RH from temp/dew point data
alpena_mi <- mutate(alpena_mi, RH=100*(exp((17.625*DewPointC)/(243.04+DewPointC))/exp((17.625*TempC)/(243.04+TempC))))
#calculation from https://bmcnoldy.rsmas.miami.edu/Humidity.html

#MONTHLY DATA
mosepa_al<-separate(alpena_mi, DATE, c("Month", "Day and Time"), sep="-") #creating a column for Month

#names(mosepa_al) #16 is RH, 12 is TempF

moavtem_al <- aggregate(mosepa_al[,12], mean, by=list(mosepa_al$Month)) #aggregating temp by month
moavRH_al <- aggregate(mosepa_al[,16], mean, by=list(mosepa_al$Month)) #aggregating RH by month

monthly_al <- merge(moavtem_al,moavRH_al,by="Group.1")
monthly_al <- monthly_al %>%
  rename(
    Month = Group.1
    )

monthly_al <- mutate(monthly_al, NAME="ALPENA CO REGIONAL AIRPORT, MI US")

##DAILY DATA

dasepa_al<-separate(alpena_mi, DATE, c("Date", "Time"), sep="T") #creating a column for Month

#names(dasepa_al) #16 is RH, 12 is TempF

daavtem_al <- aggregate(dasepa_al[,12], mean, by=list(dasepa_al$Date)) #aggregating temp by month
daavRH_al <- aggregate(dasepa_al[,16], mean, by=list(dasepa_al$Date)) #aggregating RH by month

daily_al <- merge(daavtem_al,daavRH_al,by="Group.1")
daily_al <- daily_al %>%
  rename(
    Date = Group.1
    )

daily_al <- mutate(daily_al, NAME="ALPENA CO REGIONAL AIRPORT, MI US")

Burns, OR Data

burns_or <- #both the DewPoint and Temp data are in Degrees F without the decimal for the tenths place
burns_or <- mutate(burns_or, TempF=HourlyTemp/10)
burns_or <- mutate(burns_or, TempC=(5/9)*(TempF - 32))

burns_or <- mutate(burns_or, DewPointF=HourlyDewPoint/10)
burns_or <- mutate(burns_or, DewPointC=(5/9)*(DewPointF - 32))
burns_or <- na.omit(burns_or)

#need to create RH from temp/dew point data
burns_or <- mutate(burns_or, RH=100*(exp((17.625*DewPointC)/(243.04+DewPointC))/exp((17.625*TempC)/(243.04+TempC))))
#calculation from https://bmcnoldy.rsmas.miami.edu/Humidity.html

#MONTHLY DATA
mosepa_bu<-separate(burns_or, DATE, c("Month", "Day and Time"), sep="-") #creating a column for Month

#names(mosepa_bu) #16 is RH, 12 is TempF

moavtem_bu <- aggregate(mosepa_bu[,12], mean, by=list(mosepa_bu$Month)) #aggregating temp by month
moavRH_bu <- aggregate(mosepa_bu[,16], mean, by=list(mosepa_bu$Month)) #aggregating RH by month

monthly_bu <- merge(moavtem_bu,moavRH_bu,by="Group.1")
monthly_bu <- monthly_bu %>%
  rename(
    Month = Group.1
    )

monthly_bu <- mutate(monthly_bu, NAME="BURNS MUNICIPAL AIRPORT, OR US")

##DAILY DATA

dasepa_bu<-separate(burns_or, DATE, c("Date", "Time"), sep="T") #creating a column for Month

#names(dasepa_bu) #16 is RH, 12 is TempF

daavtem_bu <- aggregate(dasepa_bu[,12], mean, by=list(dasepa_bu$Date)) #aggregating temp by month
daavRH_bu <- aggregate(dasepa_bu[,16], mean, by=list(dasepa_bu$Date)) #aggregating RH by month

daily_bu <- merge(daavtem_bu,daavRH_bu,by="Group.1")
daily_bu <- daily_bu %>%
  rename(
    Date = Group.1
    )

daily_bu <- mutate(daily_bu, NAME="BURNS MUNICIPAL AIRPORT, OR US")

Louisville, KY Data

louisville_ky <- #both the DewPoint and Temp data are in Degrees F without the decimal for the tenths place
louisville_ky <- mutate(louisville_ky, TempF=HourlyTemp/10)
louisville_ky <- mutate(louisville_ky, TempC=(5/9)*(TempF - 32))

louisville_ky <- mutate(louisville_ky, DewPointF=HourlyDewPoint/10)
louisville_ky <- mutate(louisville_ky, DewPointC=(5/9)*(DewPointF - 32))
louisville_ky <- na.omit(louisville_ky)

#need to create RH from temp/dew point data
louisville_ky <- mutate(louisville_ky, RH=100*(exp((17.625*DewPointC)/(243.04+DewPointC))/exp((17.625*TempC)/(243.04+TempC))))
#calculation from https://bmcnoldy.rsmas.miami.edu/Humidity.html

#MONTHLY DATA
mosepa_lo<-separate(louisville_ky, DATE, c("Month", "Day and Time"), sep="-") #creating a column for Month

#names(mosepa_lo) #16 is RH, 12 is TempF

moavtem_lo <- aggregate(mosepa_lo[,12], mean, by=list(mosepa_lo$Month)) #aggregating temp by month
moavRH_lo <- aggregate(mosepa_lo[,16], mean, by=list(mosepa_lo$Month)) #aggregating RH by month

monthly_lo <- merge(moavtem_lo,moavRH_lo,by="Group.1")
monthly_lo <- monthly_lo %>%
  rename(
    Month = Group.1
    )

monthly_lo <- mutate(monthly_lo, NAME="LOUISVILLE INTERNATIONAL AIRPORT, KY US")

##DAILY DATA

dasepa_lo<-separate(louisville_ky, DATE, c("Date", "Time"), sep="T") #creating a column for Month

#names(dasepa_lo) #16 is RH, 12 is TempF

daavtem_lo <- aggregate(dasepa_lo[,12], mean, by=list(dasepa_lo$Date)) #aggregating temp by month
daavRH_lo <- aggregate(dasepa_lo[,16], mean, by=list(dasepa_lo$Date)) #aggregating RH by month

daily_lo <- merge(daavtem_lo,daavRH_lo,by="Group.1")
daily_lo <- daily_lo %>%
  rename(
    Date = Group.1
    )

daily_lo <- mutate(daily_lo, NAME="LOUISVILLE INTERNATIONAL AIRPORT, KY US")

Lufkin, TX Data

lufkin_tx <- #both the DewPoint and Temp data are in Degrees F without the decimal for the tenths place
lufkin_tx <- mutate(lufkin_tx, TempF=HourlyTemp/10)
lufkin_tx <- mutate(lufkin_tx, TempC=(5/9)*(TempF - 32))

lufkin_tx <- mutate(lufkin_tx, DewPointF=HourlyDewPoint/10)
lufkin_tx <- mutate(lufkin_tx, DewPointC=(5/9)*(DewPointF - 32))
lufkin_tx <- na.omit(lufkin_tx)

#need to create RH from temp/dew point data
lufkin_tx <- mutate(lufkin_tx, RH=100*(exp((17.625*DewPointC)/(243.04+DewPointC))/exp((17.625*TempC)/(243.04+TempC))))
#calculation from https://bmcnoldy.rsmas.miami.edu/Humidity.html

#MONTHLY DATA
mosepa_lu<-separate(lufkin_tx, DATE, c("Month", "Day and Time"), sep="-") #creating a column for Month

#names(mosepa_lu) #16 is RH, 12 is TempF

moavtem_lu <- aggregate(mosepa_lu[,12], mean, by=list(mosepa_lu$Month)) #aggregating temp by month
moavRH_lu <- aggregate(mosepa_lu[,16], mean, by=list(mosepa_lu$Month)) #aggregating RH by month

monthly_lu <- merge(moavtem_lu,moavRH_lu,by="Group.1")
monthly_lu <- monthly_lu %>%
  rename(
    Month = Group.1
    )

monthly_lu <- mutate(monthly_lu, NAME="LUFKIN ANGELINA CO AIRPORT, TX US")

##DAILY DATA

dasepa_lu<-separate(lufkin_tx, DATE, c("Date", "Time"), sep="T") #creating a column for Month

#names(dasepa_lu) #16 is RH, 12 is TempF

daavtem_lu <- aggregate(dasepa_lu[,12], mean, by=list(dasepa_lu$Date)) #aggregating temp by month
daavRH_lu <- aggregate(dasepa_lu[,16], mean, by=list(dasepa_lu$Date)) #aggregating RH by month

daily_lu <- merge(daavtem_lu,daavRH_lu,by="Group.1")
daily_lu <- daily_lu %>%
  rename(
    Date = Group.1
    )

daily_lu <- mutate(daily_lu, NAME="LUFKIN ANGELINA CO AIRPORT, TX US")

Worcester, MA Data

worcester_ma <- #both the DewPoint and Temp data are in Degrees F without the decimal for the tenths place
worcester_ma <- mutate(worcester_ma, TempF=HourlyTemp/10)
worcester_ma <- mutate(worcester_ma, TempC=(5/9)*(TempF - 32))

worcester_ma <- mutate(worcester_ma, DewPointF=HourlyDewPoint/10)
worcester_ma <- mutate(worcester_ma, DewPointC=(5/9)*(DewPointF - 32))
worcester_ma <- na.omit(worcester_ma)

#need to create RH from temp/dew point data
worcester_ma <- mutate(worcester_ma, RH=100*(exp((17.625*DewPointC)/(243.04+DewPointC))/exp((17.625*TempC)/(243.04+TempC))))
#calculation from https://bmcnoldy.rsmas.miami.edu/Humidity.html

#MONTHLY DATA
mosepa_wo<-separate(worcester_ma, DATE, c("Month", "Day and Time"), sep="-") #creating a column for Month

#names(mosepa_wo) #16 is RH, 12 is TempF

moavtem_wo <- aggregate(mosepa_wo[,12], mean, by=list(mosepa_wo$Month)) #aggregating temp by month
moavRH_wo <- aggregate(mosepa_wo[,16], mean, by=list(mosepa_wo$Month)) #aggregating RH by month

monthly_wo <- merge(moavtem_wo,moavRH_wo,by="Group.1")
monthly_wo <- monthly_wo %>%
  rename(
    Month = Group.1
    )

monthly_wo <- mutate(monthly_wo, NAME="WORCESTER, MA US")

##DAILY DATA

dasepa_wo<-separate(worcester_ma, DATE, c("Date", "Time"), sep="T") #creating a column for Month

#names(dasepa_wo) #16 is RH, 12 is TempF

daavtem_wo <- aggregate(dasepa_wo[,12], mean, by=list(dasepa_wo$Date)) #aggregating temp by month
daavRH_wo <- aggregate(dasepa_wo[,16], mean, by=list(dasepa_wo$Date)) #aggregating RH by month

daily_wo <- merge(daavtem_wo,daavRH_wo,by="Group.1")
daily_wo <- daily_wo %>%
  rename(
    Date = Group.1
    )

daily_wo <- mutate(daily_wo, NAME="WORCESTER, MA US")

Combining the Cities, Graphing

library(ggplot2)
library(hrbrthemes)
dafivecit<-rbind(daily_al,daily_bu,daily_lo,daily_lu,daily_wo) #compiling the datasets into one
dafivecit$Date <- as.Date(dafivecit$Date, "%m-%d")
dafivecit <- mutate(
  dafivecit,
  city = ifelse(grepl("ALPENA", NAME), "Alpena, MI", ifelse(
    grepl("BURNS", NAME), "Burns, OR", ifelse(
      grepl("LOUISVILLE", NAME), "Louisville, KY", ifelse(
        grepl("LUFKIN", NAME), "Lufkin, TX", "Worcester, MA")
        )
      )
    )
  )

#dafivecit$Date <- format(dafivecit$Date, format="%m")

dafivecit %>%
  ggplot( aes(x=Date, y=TempF, group=city, color=city)) +
    geom_line() +
    ggtitle("Average Daily Temperature by City") +
    theme_ipsum() +
    scale_x_date(name="Month", date_labels = "%B") +
    scale_y_continuous(name="Temperature °F")

dafivecit %>%
  ggplot( aes(x=Date, y=RH, group=city, color=city)) +
    geom_line() +
    ggtitle("Average Daily RH by City") +
    theme_ipsum() +
    scale_x_date(name="Month", date_labels = "%B") +
    scale_y_continuous(name="Temperature °F")

The average monthly temperature in each city seems to be normally distributed with peaks for all cities around July. In order of warmest to coolest: Lufkin, TX > Lousiville, KY > Worcester, MA > Alpena, MI > Burns, OR. Cities like Alpena, Burns, and Worcester (whose monthly average peaks below 70F in July) are probably much more susceptible to extreme heat days than are Louisville and Lufkin, whose infrastructure is designed to withstand extreme heat. This could result in excess mortality on days that reach record hots for the coler cities. While excess mortality may not be the danger of extreme cold days for Lufkin, TX, as climate change increases the mean and variance of weather events, it’s likely that Lufkin will see more frequent extreme cold days. As we have seen with Texas in 2021, the infrastructure in usually hot climes are not prepared for “winter weather” which could disrupt power, water, and business infrastructure for weeks at a time.

Relative humidity has an influence on infectious disease epidemiology. Airborne-transmitted bacteria and viruses have reduced infectivity/survival in RHs between 40-70%. Indoor allergens like mites are best eliminated at RH < 40% and maximized at RH > 80%. Similarly, most fungi growth is impeded in RH < 60%. Arundel et al. suggest that “The majority of adverse health effects caused by relative humidity would be minimized by maintaining indoor levels between 40 and 60%” (doi: https://doi.org/10.1289/ehp.8665351). It seems that Burns, OR, is at the greatest risk (of these five cities) to experience adverse health impacts related to low RH, with their highest-risk occurring around July. Burns, OR, and Alpena, MI, both experience high-humidity risk in the winter months.

Question 3

Provide contrasting monthly and seasonal variations in temperature and humidity of these five cities (2 points).

Combining the Cities, Graphing

mofivecit<-rbind(monthly_al,monthly_bu,monthly_lo,monthly_lu,monthly_wo) #compiling the datasets into one
library(ggplot2)
#Temp
mofivecit$Month<-as.numeric(mofivecit$Month)
ggplot(mofivecit, 
       aes(x = Month, 
           y = TempF, 
           color = NAME)) +
  geom_point(alpha = .4, 
             size = 3) +
  geom_smooth(se=FALSE, 
              method = "lm", 
              formula = y ~ poly(x, 4), 
              size = 1.5) +
  labs(x = "Month",
       title = "Average Temperature by Month and City",
       subtitle = "from Hourly Average Data, 1981 to 2010",
       y = "Temperature (Degrees F)",
       color = "NAME") +
  scale_y_continuous() +
  scale_x_continuous(breaks=seq(1, 12, 2)) +
  scale_color_brewer(palette = "Set1") +
  theme(legend.position="bottom") +
  theme_minimal()

#RH

mofivecit$RH<-as.numeric(mofivecit$RH)
ggplot(mofivecit, 
       aes(x = Month, 
           y = RH, 
           color = NAME)) +
  geom_point(alpha = .4, 
             size = 3) +
  geom_smooth(se=FALSE, 
              method = "lm", 
              formula = y ~ poly(x, 4), 
              size = 1.5) +
  labs(x = "Month",
       title = "Average Relative Humidity by Month and City",
       subtitle = "from Hourly Average Data, 1981 to 2010",
       y = "Relative Humidity (%)",
       color = "NAME") +
  scale_y_continuous() +
  scale_x_continuous(breaks=seq(1, 12, 2)) +
  scale_color_brewer(palette = "Set1") +
  theme_minimal()