Skip to content

Instantly share code, notes, and snippets.

@smach
Last active January 14, 2022 22:23
Show Gist options
  • Save smach/897ee745d0cbcac6160952cc8f9da8fc to your computer and use it in GitHub Desktop.
Save smach/897ee745d0cbcac6160952cc8f9da8fc to your computer and use it in GitHub Desktop.
get_forecast_data <- function(city, forecast_url) {
req<-httr::GET(forecast_url)
json <- httr::content(req, as = "text")
weather_data <- jsonlite::fromJSON(json)
forecast_df <- weather_data$properties$periods
forecast_df <- forecast_df %>%
dplyr::mutate(
City = city,
Temp = if_else(isDaytime == TRUE, "High", "Low"),
Date = as.Date(substr(startTime,1,10)),
Day = factor(name, levels = unique(name), ordered = TRUE)
)
Sys.sleep(2)
return(forecast_df)
}
get_forecast_graph <- function(forecast_df) {
ggplot(forecast_df, aes(x = Date, y = temperature, group = Temp, color = Temp)) +
geom_line() +
theme_minimal() +
theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "gray")) +
ylab("") + xlab("")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment