Skip to content

Instantly share code, notes, and snippets.

@dggoldst
Last active January 25, 2019 03:15
Show Gist options
  • Save dggoldst/456458b680eb937d8507bf92de89dbb5 to your computer and use it in GitHub Desktop.
Save dggoldst/456458b680eb937d8507bf92de89dbb5 to your computer and use it in GitHub Desktop.
library(tidyverse)
#Wind speeds from the percentile bands in
#https://weatherspark.com/y/23912/Average-Weather-in-New-York-City-New-York-United-States-Year-Round
#https://weatherspark.com/y/14091/Average-Weather-in-Chicago-Illinois-United-States-Year-Round
#weather.gov wind chill chart at https://www.weather.gov/safety/cold-wind-chill-chart
get_wind_chill = function(temp,wind){
35.74 + .6251*temp - 35.75 * wind^.16 + .4275 * temp * wind^.16
}
toC = function(F) {(F - 32) * 5 / 9}
speeds = c(10,15,25)
mini_df = data.frame(temp=c(35,35,27.5,27.5),
wind=c(10,16,14,22),
lab=c("NYC Avg","NYC Windy","Chicago Avg","Chicago Windy")
) %>%
mutate(
wind_speed = factor(wind, levels = speeds),
wind_chill = round(get_wind_chill(temp,wind),0))
df = expand.grid(temp = seq(5, 40, by = 2), wind = speeds) %>%
mutate(
wind_speed = factor(wind, levels = speeds),
wind_chill = round(get_wind_chill(temp,wind),2))
p=ggplot(df,aes(x=temp,y=wind_chill-temp, group=wind_speed, color=wind_speed))
p = p + geom_line(size = 1) +
ylim(c(-25,0)) +
theme_bw() +
labs(x = "Temperature", y = "Adjustment to temperature\nto get wind chill (F)") +
geom_text(show.legend=FALSE,data=mini_df,
aes(x=temp,y=wind_chill-temp+1.25,label=lab,group=NULL,color=NULL)) +
geom_point(show.legend=FALSE,data=mini_df,size=2,
aes(x=temp,y=wind_chill-temp,group=NULL,color=NULL)) +
theme(legend.position = "bottom")
p
ggsave(plot=p,file="windchill_chicago_nyc.png",width=6,height=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment