Updated by NDG 2/7/24
You have been hired as a consultant by Disney to create a location for a new amusement park. Your job is to analyze weather data from different locations to pick out the best option.
Begin by looking at the documentation for the climate normal data.
Then load your ClimateNormalData.csv datafile. You will need to do some clean-up. Be sure to look at the data carefully. Below are a list of suggested dplyr activities.
Suggested tasks:
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.2.3
## Warning: package 'ggplot2' was built under R version 4.2.3
## Warning: package 'tibble' was built under R version 4.2.3
## Warning: package 'tidyr' was built under R version 4.2.3
## Warning: package 'readr' was built under R version 4.2.3
## Warning: package 'purrr' was built under R version 4.2.3
## Warning: package 'dplyr' was built under R version 4.2.3
## Warning: package 'stringr' was built under R version 4.2.3
## Warning: package 'forcats' was built under R version 4.2.3
## Warning: package 'lubridate' was built under R version 4.2.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── 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(lubridate)
#- Load both csv files as raw data
t_raw <- read_csv("ClimateNormalData.csv",
col_names = TRUE,
skip = 3)
## Rows: 35040 Columns: 57
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): STATION, month, day, hour
## dbl (52): HLY-TEMP-NORMAL, years_HLY-TEMP-NORMAL, HLY-TEMP-10PCTL, years_HLY...
## lgl (1): meas_flag_HLY-DEWP-10PCTL
##
## ℹ 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.
t_stations_raw <- read_csv("ClimateNormalData_stations.csv",
col_names= TRUE,
skip = 2)
## Rows: 4 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): STATION, NAME
## dbl (3): LATITUDE, LONGITUDE, ELEVATION
##
## ℹ 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.
t_climate_normal <- left_join(t_stations_raw, t_raw, by = "STATION")
t_climate_normal_with_date <- t_climate_normal |>
mutate(month = as.integer(month),
day = as.integer(day),
date = mdy(paste(month, day, 2024))) |>
select(-LONGITUDE, -LATITUDE, -NAME, -month, -day, -contains('years')) |>
relocate(ELEVATION, .after = hour) |>
relocate(date, .before = hour)
#- Cleanup the data #- Turn all character date fields into integers
#- Create a new string with paste or paste0 that has m/d/y (use 2024 for year) # - Use mdy from lubridate to create an actual date column # - Remove any fields you don’t want to use
#- Join the two tables together to get the titles for each station.
Now that you have the data, create some basic summary data. Show a table with the average temperature by month and location. Have the stations as rows, and the month as columns.
Hint: you may need to use dplyr pivot.
summary_table <- t_climate_normal |>
group_by(STATION, month) |>
summarize(avg_temp = mean(`HLY-TEMP-NORMAL`)) |>
pivot_wider(names_from = "month", values_from = "avg_temp")
## `summarise()` has grouped output by 'STATION'. You can override using the
## `.groups` argument.
# Part 3: Best location for amusement park (5 points)
#We want to find the best location for an amusement park that isn't too hot, or too cold.
#Define an appropriate temperature range where it is comfortable to be outside. Then, create a graph showing how different locations meet your temperature requirement.
#Write a brief 2-3 sentence explanation of your findings.
library(ggplot2)
ggplot(t_climate_normal) +
aes(x = `HLY-TEMP-NORMAL`, y = NAME, colour = month) +
geom_violin(adjust = 1L,
scale = "area", fill = "#112446") +
scale_color_hue(direction = 1) +
theme_minimal()
#i would likely define a temperate location as one where the average temperature is greater than 50 but less than 95 on a given day.
#it appears that TX or PA would be the best for these criteria, and AK would be the worst. NY and PA are not bad choices, but given the higher frequency of cold during early months, i'd say texas is superior (i am biased towards warmth)
#Which of the sites would be best as an airport? Explore the others variables in your dataset. For example, look at cloud cover or average wind speed. This may require some data clean, so carefully look at your dataset for weird values.
best_as_airport <- t_climate_normal |>
select(STATION, NAME, `HLY-CLOD-PCTCLR`, `HLY-CLOD-PCTOVC`,`HLY-WIND-PCTCLM`,`HLY-WIND-AVGSPD`) |>
filter(`HLY-CLOD-PCTCLR` >= 0, `HLY-CLOD-PCTOVC` >= 0, `HLY-WIND-PCTCLM` >= 0, `HLY-WIND-AVGSPD` >= 0)
library(ggplot2)
#An airport would likely require a site that has a relatively low overcast cloud percentage (for visibility), a low average wind speed, (for safety during takeoff/landing), and a high percentage of calm and of clear weather (for safety and visibility)
ggplot(best_as_airport) +
aes(x = `HLY-CLOD-PCTOVC`, y = `HLY-CLOD-PCTCLR`, colour = NAME) +
geom_point(shape = "circle",
size = 1.5) +
scale_color_hue(direction = 1) +
theme_minimal()
#this chart shows each individual observation and the percentage of clear (y) vs the percentage of overcast (x). It appears that PA is the most likely to be clear & AK is the most likely to be overcast. by this metric it appears that PA would be best for an airport since it is clear for most of the observations.
#Give a chart, and write a 2-3 sentence explanation of your answer.