The U.S. Daily Climate Normals (1981-2010) dataset provides a comprehensive overview of average daily meteorological conditions across the United States and its territories. This dataset is a valuable resource for understanding typical climate patterns, including temperature, precipitation, and other weather variables.
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.4.1
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(corrplot)
## Warning: package 'corrplot' was built under R version 4.4.1
## corrplot 0.94 loaded
climate_data <- read_csv("NORMAL_DLY_sample_csv.csv")
## Rows: 365 Columns: 9
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): STATION, STATION_NAME
## dbl (7): ELEVATION, LATITUDE, LONGITUDE, DATE, DLY-TMIN-NORMAL, DLY-TMAX-NOR...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
missing_values <- sum(is.na(climate_data))
if (missing_values == 0) {
message("There are 0 empty values in the dataset.")
} else {
message(paste("There are", missing_values, "empty values in the dataset."))
}
## There are 0 empty values in the dataset.
head(climate_data)
## # A tibble: 6 × 9
## STATION STATION_NAME ELEVATION LATITUDE LONGITUDE DATE `DLY-TMIN-NORMAL`
## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 GHCND:USC0… PETERSBURG … 466. 48.0 -98.0 2.01e7 -33
## 2 GHCND:USC0… PETERSBURG … 466. 48.0 -98.0 2.01e7 -35
## 3 GHCND:USC0… PETERSBURG … 466. 48.0 -98.0 2.01e7 -36
## 4 GHCND:USC0… PETERSBURG … 466. 48.0 -98.0 2.01e7 -38
## 5 GHCND:USC0… PETERSBURG … 466. 48.0 -98.0 2.01e7 -39
## 6 GHCND:USC0… PETERSBURG … 466. 48.0 -98.0 2.01e7 -41
## # ℹ 2 more variables: `DLY-TMAX-NORMAL` <dbl>, `MTD-PRCP-NORMAL` <dbl>
summary(climate_data)
## STATION STATION_NAME ELEVATION LATITUDE
## Length:365 Length:365 Min. :466.3 Min. :48.04
## Class :character Class :character 1st Qu.:466.3 1st Qu.:48.04
## Mode :character Mode :character Median :466.3 Median :48.04
## Mean :466.3 Mean :48.04
## 3rd Qu.:466.3 3rd Qu.:48.04
## Max. :466.3 Max. :48.04
## LONGITUDE DATE DLY-TMIN-NORMAL DLY-TMAX-NORMAL
## Min. :-98.01 Min. :20100101 Min. :-48 Min. :138.0
## 1st Qu.:-98.01 1st Qu.:20100402 1st Qu.: 73 1st Qu.:247.0
## Median :-98.01 Median :20100702 Median :307 Median :531.0
## Mean :-98.01 Mean :20100668 Mean :282 Mean :493.2
## 3rd Qu.:-98.01 3rd Qu.:20101001 3rd Qu.:489 3rd Qu.:725.0
## Max. :-98.01 Max. :20101231 Max. :567 Max. :805.0
## MTD-PRCP-NORMAL
## Min. : 1.00
## 1st Qu.: 27.00
## Median : 56.00
## Mean : 87.59
## 3rd Qu.:131.00
## Max. :376.00
summary(climate_data[, c("DLY-TMIN-NORMAL", "DLY-TMAX-NORMAL", "MTD-PRCP-NORMAL")])
## DLY-TMIN-NORMAL DLY-TMAX-NORMAL MTD-PRCP-NORMAL
## Min. :-48 Min. :138.0 Min. : 1.00
## 1st Qu.: 73 1st Qu.:247.0 1st Qu.: 27.00
## Median :307 Median :531.0 Median : 56.00
## Mean :282 Mean :493.2 Mean : 87.59
## 3rd Qu.:489 3rd Qu.:725.0 3rd Qu.:131.00
## Max. :567 Max. :805.0 Max. :376.00
hist(climate_data$`DLY-TMIN-NORMAL`, main = "Histogram of Daily Minimum Temperature")
hist(climate_data$`DLY-TMAX-NORMAL`, main = "Histogram of Daily Maximum Temperature")
hist(climate_data$`MTD-PRCP-NORMAL`, main = "Histogram of Monthly Total Precipitation")
correlation_matrix <- cor(climate_data[, c("DLY-TMIN-NORMAL", "DLY-TMAX-NORMAL", "MTD-PRCP-NORMAL")])
corrplot(correlation_matrix, method = "circle", type = "upper")
model <- lm(`DLY-TMIN-NORMAL` ~ `DLY-TMAX-NORMAL`, data = climate_data)
summary(model)
##
## Call:
## lm(formula = `DLY-TMIN-NORMAL` ~ `DLY-TMAX-NORMAL`, data = climate_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -22.4337 -13.9647 -0.9196 14.2645 27.1539
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.605e+02 1.788e+00 -89.74 <2e-16 ***
## `DLY-TMAX-NORMAL` 8.973e-01 3.267e-03 274.66 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 14.83 on 363 degrees of freedom
## Multiple R-squared: 0.9952, Adjusted R-squared: 0.9952
## F-statistic: 7.544e+04 on 1 and 363 DF, p-value: < 2.2e-16
ggplot(climate_data, aes(x = `DLY-TMAX-NORMAL`, y = `DLY-TMIN-NORMAL`)) +
geom_point() +
geom_abline(intercept = coef(model)[1], slope = coef(model)[2], color = "red") +
labs(x = "Daily Maximum Temperature", y = "Daily Minimum Temperature") +
ggtitle("Scatter Plot: Daily Minimum Temperature vs. Daily Maximum Temperature")