-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
181 lines (132 loc) · 4.2 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
179
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
fig.retina = 2 ,
out.width = "100%",
message = FALSE,
warning = FALSE
)
```
# weather <img src="man/figures/france-meteo.png" width=450 align="right" />
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![R-CMD-check](https://github.com/dreamRs/weather/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dreamRs/weather/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
> Use [weather-icons](https://erikflowers.github.io/weather-icons/) in ggplot2, markdown and shiny.
```{r, echo=FALSE}
# knitr::include_graphics(path = "man/figures/meteo-france-2.png")
```
<!-- ![](man/figures/meteo-france-2.png) -->
## Installation
You can install the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("dreamRs/weather")
```
## ggplot2
Plot weather icons with `geom_weather` :
```{r example-ggplot2, fig.height=3}
library(ggplot2)
library(weather)
df <- data.frame(
hour = seq(as.POSIXct("2017-04-11"), by = "6 hour", length.out = 5),
temperature = c(5, 4, 12, 10, 6),
weather = c("night-clear", "day-rain-mix",
"day-cloudy", "day-sunny",
"night-alt-cloudy")
)
ggplot(data = df) +
geom_line(aes(hour, temperature)) +
geom_weather(aes(hour, temperature, weather = weather)) +
theme_minimal()
```
Icons available are listed in `weather_icon_names`.
Or plot on a map:
```{r weather-map, eval=FALSE}
library(ggplot2)
library(weather)
library(darksky)
library(sf)
# devtools::install_github("antuki/CARTElette/CARTElette@RPackage")
library(CARTElette)
# Get forecast for some cities
fr_now <- mapply(
FUN = function(latitude, longitude) {
res <- get_current_forecast(
latitude = latitude,
longitude = longitude,
exclude = "currently,minutely,hourly,alerts,flags"
)
res <- res$daily
res$lat <- latitude
res$lon <- longitude
res
},
latitude = c(48.86, 43.31, 45.76, 43.62, 43.7, 47.23, 48.58, 43.61, 50.64,
44.84, 48.11, 49.25, 49.5, 45.43, 47.48),
longitude = c(2.34, 5.37, 4.83, 1.45, 7.27, -1.57, 7.76, 3.87, 3.07, -0.58,
-1.68, 4.03, 0.12, 4.39, -0.54),
SIMPLIFY = FALSE
)
fr_now <- do.call("rbind", fr_now)
fr_tomorrow <- fr_now[as.character(fr_now$time) == Sys.Date() + 1, ]
# Load France polygons
france <- charger_carte(nivsupra = "REG")
france <- sf::st_transform(france, crs = 4326)
ggplot(data = france) +
geom_sf(fill = "white") +
geom_weather(
data = fr_tomorrow,
mapping = aes(lon, lat, weather = icon),
api = "darksky"
) +
theme_minimal() +
labs(
title = paste(
"Pr\u00e9visions du",
format(fr_tomorrow$time[1], format = "%A %d %B")
),
subtitle = paste("\u00e0", format(Sys.time(), format = "%H:%M le %d/%m"))
)
```
![](man/figures/README-weather-map-1.png)
## rmarkdown and shiny
Display icons in rmarkdown document and shiny application with `weather_icon`. You can control size and color :
```{r, eval=FALSE}
weather_icon("day-sunny", size = "50px", color = "goldenrod")
```
Example in shiny:
```{r, eval=FALSE}
navbarPage(
title = "App Title",
tabPanel(
title = "Plot", icon = weather_icon("sunrise"),
actionButton("go", "a button", icon = weather_icon("day-rain"))
),
tabPanel("Summary", icon = weather_icon("cloud")),
tabPanel("Table", icon = weather_icon("tornado"))
)
```
![](man/figures/shiny-example.png)
In shinydashboard:
```{r, eval=FALSE}
# In sidebar
menuItem("Weather", tabName = "Weather", icon = weather_icon("day-rain"))
# In infoBox
infoBox(
"Temperature", "17.2", "Subtitle", icon = weather_icon("thermometer")
)
# In valueBox
valueBox(
"Sky clear", "cloud cover", icon = weather_icon("day-sunny")
)
```
![](man/figures/shinydashboard-example.png)
## Note
`geom_weather` is largely inspired by `ggflags` (https://github.com/ellisp/ggflags & https://github.com/rensa/ggflags).