-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
README.Rmd
178 lines (150 loc) · 5.19 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
---
output: rmarkdown::github_document
editor_options:
chunk_output_type: console
---
```{r pkg-knitr-opts, include=FALSE}
hrbrpkghelpr::global_opts()
```
```{r badges, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::stinking_badges()
```
```{r description, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::yank_title_and_description()
```
## What's Inside The Tin
The following functions are implemented:
```{r ingredients, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::describe_ingredients()
```
## Installation
```{r install-ex, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::install_block()
```
## NOTE
Please reference the local [Authorization](authorization.md) documentation or use `vignette("authorization", package="weatherkit")` at an R console for information on how to obtain the necessary authentication and signing components required to use the WeatherKit REST API from this package.
If your apps, web apps, or websites display any Apple weather data (other than weather alerts or value-added services or products, as described below), you must clearly display the Apple Weather trademark ( Weather), as well as the [legal link to other data sources](https://weatherkit.apple.com/legal-attribution.html).
## Usage
```{r lib-ex}
library(weatherkit)
library(ragg)
# current version
packageVersion("weatherkit")
```
```{r availability}
wxkit_availability(43.2683199, -70.8635506, "US")
```
```{r weather}
wx <- wxkit_weather(43.2683199, -70.8635506)
wx <- wx_tidy(wx)
str(wx)
```
```{r current-conditions}
current_conditions(wx)
```
```{r hourly-forecast}
hourly_forecast(wx)
```
```{r daily-forecast}
daily_forecast(wx)
```
```{r wx-alerts, eval=FALSE}
# weatherAlerts structure
List of 4
$ name : chr "WeatherAlertCollection"
$ metadata :List of 9
$ detailsUrl: chr "https://weather-data.apple.com/alertDetails/index.html?ids=55f14171-c72f-5340-8003-9b51e52d14e5&lang=en-US&time"| __truncated__
$ alerts :'data.frame': 1 obs. of 18 variables:
> str(y$weatherAlerts)
List of 4
$ name : chr "WeatherAlertCollection"
$ metadata :List of 9
..$ attributionURL: chr "https://weather-data.apple.com/legal-attribution.html"
..$ expireTime : chr "2022-07-28T18:13:02Z"
..$ language : chr "en-US"
..$ latitude : num 43.3
..$ longitude : num -70.9
..$ providerName : chr "National Weather Service"
..$ readTime : chr "2022-07-28T18:08:02Z"
..$ reportedTime : chr "2022-07-28T18:08:02Z"
..$ version : int 1
$ detailsUrl: chr "https://weather-data.apple.com/alertDetails/index.html?ids=55f14171-c72f-5340-8003-9b51e52d14e5&lang=en-US&time"| __truncated__
$ alerts :'data.frame': 1 obs. of 18 variables:
..$ name : chr "WeatherAlertSummary"
..$ id : chr "55f14171-c72f-5340-8003-9b51e52d14e5"
..$ areaId : chr "mez018"
..$ areaName : chr "Interior York"
..$ countryCode : chr "US"
..$ description : chr "Special Weather Statement"
..$ effectiveTime: chr "2022-07-28T17:42:00Z"
..$ expireTime : chr "2022-07-28T19:00:00Z"
..$ issuedTime : chr "2022-07-28T17:42:00Z"
..$ detailsUrl : chr "https://weather-data.apple.com/alertDetails/index.html?ids=55f14171-c72f-5340-8003-9b51e52d14e5&lang=en-US&time"| __truncated__
..$ precedence : int 0
..$ severity : chr "minor"
..$ source : chr "National Weather Service"
..$ eventSource : chr "US"
..$ urgency : chr "expected"
..$ certainty : chr "observed"
..$ importance : chr "low"
..$ responses :List of 1
.. ..$ : list()
```
```{r temps, dev="ragg_png", fig.width=800/96, fig.height=500/96}
library(ggtext)
library(ggforce)
library(hrbragg) # remotes::install_github("hrbrmstr/hrbragg")
library(ggplot2)
library(weatherkit)
data.frame(
x = celsius_to_fahrenheit(wx$forecastDaily$days$temperatureMin),
xend = celsius_to_fahrenheit(wx$forecastDaily$days$temperatureMax),
y = as.integer(as.Date(wx$forecastDaily$days$forecastStart))
) -> xdf
xdf |>
ggplot() +
geom_link(
aes(
x, y, xend=xend, yend=y,
colour = stat(index)
),
linewidth = 4, # remotes::install_github("tidyverse/ggplot2")
lineend = "round",
show.legend = FALSE
) +
scale_x_continuous(
name = NULL,
label = function(x) sprintf("%s°F", x),
sec.axis = dup_axis()
) +
scale_y_reverse(
name = NULL,
breaks = seq_rng(xdf$y),
labels = function(x) {
x <- as.Date(x, origin="1970-01-01")
ifelse(x == Sys.Date(), "Today", strftime(x, "%a"))
},
sec.axis = dup_axis()
) +
scale_colour_viridis_c(
option = "cividis"
) +
labs(
title = "Weather for Berwick, Maine"
) +
theme_gs(grid="XY", axis_text_size = 12) +
theme(
axis.title.x.top = element_blank(),
axis.text.y.left = element_markdown(family = "Inter"),
axis.text.y.right = element_markdown(family = "Inter"),
panel.grid.major.x = element_line(linetype = "dotted", size = 0.5),
panel.grid.major.y = element_line(linetype = "dotted", size = 0.5)
)
```
## weatherkit Metrics
```{r cloc, echo=FALSE}
cloc::cloc_pkg_md()
```
## Code of Conduct
Please note that this project is released with a Contributor Code of Conduct.
By participating in this project you agree to abide by its terms.