Plotting precip Data (by time and station)
#Precipitation over Days Scatter Plot For Each Station
date <- unique(data[, 6]) #date
date <- format(sort(date)) #sorting dates and converting from numeric to char string
date2 <- as.Date(date, format = "%Y%m%d") #converting dates into proper date format
station_ids_names <- unique(data[, 1:2]) #station names
good <- 1:36
good <- good[-c(3, 9, 19, 20, 21, 35)] #takes out stations that don't have precipitations
for (i in good){ #loop goes through stations that have precipitations
indicator <- !is.na(precip[,i]) #indicator variable to take out NAs of plots
station_title <- paste(station_ids_names[i ,2],
"Precipitation") #changing title for each station for plots
plot(date2[indicator], precip[indicator, i], col = "blue", main = station_title,
xlab = "Time (days)", ylab = "Precipitation (in)", type = "h")
}
#Cal Poly SLO Plot
indicator <- !is.na(precip[,35])
station_title <- "Cal Poly SLO Precipitation"
plot(date2[indicator], precip[indicator, 35], col = "blue", main = station_title,
xlab = "Time (days)", ylab = "Precipitation (in)", type = "h")
Plotting temps_min and temps_max Data (by time and station)
#Temperatures over Time Scatter Plot
station_ids_names <- unique(data[, 1:2]) #station ids and names
date <- unique(data[, 6]) #date
date <- format(sort(date)) #sorting dates and converting from numeric to character string
date2 <- as.Date(date, format = "%Y%m%d")
good2 <- 1:36
good2 <- good2[-c(2, 6, 7, 8, 13, 16, 22,
23, 24, 26, 27, 30, 31,
32, 33, 34, 35, 36)] #removing all stations without min and max temperatures
for (x in good2) { #loops through all stations with min and max temperatures
indicator <- !is.na(temps_min[,x]) & #indicator to remove NAs from plot
!is.na(temps_max[,x])
temp_title <- paste(station_ids_names[x, 2], "Max/Min Temperatures") #changing title
temp_d <- date2[indicator]
y1 <- temps_min[indicator, x]
y2 <- temps_max[indicator, x]
yr <- range(c(y1, y2))
plot(temp_d, y1, type = "p", pch = 1, main = temp_title, xlab = "Time (days)",
ylab = "Temperature (Fahrenheit)", col = "blue", ylim = yr)
points(temp_d, y2, type = "p", pch = 1, col = "red")
abline(lm(y1~temp_d), lwd = 2)
abline(lm(y2~temp_d), lwd = 2)
}