Skip to content

Instantly share code, notes, and snippets.

@m-sostero
Created August 31, 2018 10:27
Show Gist options
  • Save m-sostero/a1165a1dbb91a4bbb33ef33629c6a2d9 to your computer and use it in GitHub Desktop.
Save m-sostero/a1165a1dbb91a4bbb33ef33629c6a2d9 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(ggmap)
library(glue)
library(lubridate)
library(suncalc)
library(hms)
theme_set(theme_minimal())
location <- "Romano d'Ezzelino"
coordinates <- geocode(location)
ephemerides <- getSunlightTimes(
date = ymd("2018/01/01") + days(0:364),
lat = coordinates$lat,
lon = coordinates$lon,
tz = "CET"
) %>% as.tibble()
eph_plot <- ephemerides %>%
select(date, sunrise, sunset, solarNoon) %>%
gather("event", "time", -date) %>%
mutate(
date = as.Date.character(date),
time = as.hms(time, tz = "CET"),
event = recode_factor(event, "sunset" = "Tramonto", "solarNoon" = "Zenit", "sunrise" = "Alba")
)
eph_plot %>%
ggplot(aes(x = date, y = time, group = event, color = event)) +
geom_line() +
scale_x_date(date_breaks = "1 month", date_labels = "%b", minor_breaks = NULL) +
scale_y_time(breaks = c(min(eph_plot$time), hms(hours = seq(6, 20, by = 2)), max(eph_plot$time))) +
labs(
x = "Mese", y = "Ora",
title = glue("Orari solari durante l'anno a {location}"),
subtitle = "Secondo ora in vigore al momento (ora solare o legale)"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment