-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
246 lines (163 loc) · 6.54 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
---
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-",
out.width = "100%"
)
library(ggraph)
library(tidygraph)
library(dplyr)
library(sf)
library(rgl)
library(knitr)
library(ggplot2)
library(devoutrgl)
set.seed(1)
```
```{r echo = FALSE, eval = FALSE}
if (FALSE) {
pkgdown::build_site(override = list(destination = "../coolbutuseless.github.io/package/devoutrgl"))
}
```
# devoutrgl <img src="man/figures/logo-new.png" align="right" height=300/>
<!-- badges: start -->
![](https://img.shields.io/badge/cool-useless-green.svg)
![](http://img.shields.io/badge/dev-out-blue.svg)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
<!-- badges: end -->
`devoutrgl::rgldev()` is a graphics device - like `pdf()` or `png()`. This device
will render a plot as an interactive 3d opengl document using `{rgl}`.
**NOTE: Since Github does not allow webgl rendering in README files, all plots
on GitHub have been rendered as PNGs or animated gifs. Please
visit [the package website](https://coolbutuseless.github.io/package/devoutrgl)
to interact with the generated output in the vignettes**
## What's in the box:
* `rgldev()` is the rgl device. Use it like you would use the `pdf()` device or the
`png()` device.
## Installation
You can install from [GitHub](https://github.com/coolbutuseless/devoutrgl) with:
``` r
# install.packages("remotes")
remotes::install_github("coolbutuseless/snowcrash") # Store R objects as images
remotes::install_github("coolbutuseless/cryogenic") # Freeze R calls + replay
remotes::install_github("coolbutuseless/triangular") # Polygon Triangulation
remotes::install_github("coolbutuseless/devout") # R device framework
remotes::install_github("coolbutuseless/devoutrgl") # This device
```
## Limitations
* No font selection. Everything will be in the default sans serif!
* Multi-line text in a single string with "\n" characters does not render well.
* No support for clipping paths.
# Examples
Bar Plot
------------------------------------------------------------------------------
```{r eval=FALSE}
library(ggplot2)
library(devoutrgl)
plot_df <- data.frame(x=c('a', 'b', 'c'), y=4:6)
p <- ggplot(plot_df) +
geom_bar(aes(x, y, fill=x), colour = NA, stat='identity') +
labs(title = "{devoutrgl}") +
scale_fill_brewer(type = 'seq', palette = 'Blues') +
theme_minimal() + theme_rgl()
devoutrgl::rgldev(fov = 30, view_angle = -30)
p
invisible(dev.off())
```
View an interactive version of this plot in the <a href="https://coolbutuseless.github.io/package/devoutrgl/articles/simple-examples.html">online documentation</a>
<img src="man/figures/bar.png" />
Base plot
------------------------------------------------------------------------------
```{r eval = FALSE}
devoutrgl::rgldev(fov = 30, view = 'flat', view_angle = 30, zoom = 0.6, filename = "man/figures/pie.png")
pie(c(cool=1, but = 2, use=3, less = 4))
dev.off()
```
View an interactive version of this plot in the <a href="https://coolbutuseless.github.io/package/devoutrgl/articles/simple-examples.html">online documentation</a>
<img src="man/figures/pie.png" />
Polygon with a hole
------------------------------------------------------------------------------
# Polygon with a hole
```{r}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# polygons_df - data.frame of polygon vertices with group/subgroups
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
polygons_df <- df <- data.frame(
x = c(4, 8, 8, 4, 6, 7, 7, 6),
y = c(4, 4, 8, 8, 6, 6, 7, 7),
group = c(1, 1, 1, 1, 1, 1, 1, 1),
subgroup = c(1, 1, 1, 1, 2, 2, 2, 2)
)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Plot
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
p <- ggplot(polygons_df) +
geom_polygon(aes(x, y, group=group, subgroup=subgroup)) +
geom_path(aes(x, y, group = interaction(group, subgroup)), colour = 'red') +
theme_bw() +
coord_equal() +
labs(title = "{devoutrgl} polygon with a hole")
rgldev(fov = 30, view_angle = -30, zoom = 0.8)
p
invisible(dev.off())
```
View an interactive version of this plot in the <a href="https://coolbutuseless.github.io/package/devoutrgl/articles/simple-examples.html">online documentation</a>
```{r echo=FALSE, eval=FALSE}
save_animated_scene("man/figures/polygon-with-hole.gif")
# system('ffmpeg -i man/figures/density.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" man/figures/polygon-with-hole.mp4')
```
<img src="man/figures/polygon-with-hole.gif" />
Density Plot
------------------------------------------------------------------------------
```{r eval=FALSE}
library(ggplot2)
library(devoutrgl)
p <- ggplot(mtcars) +
geom_density(aes(mpg, fill=as.factor(cyl)), colour = '#ffffff00') +
theme(legend.position = 'none') +
scale_fill_brewer(palette = 'Set1') +
theme_bw() +
labs(title = "{devoutrgl} geom_density()")
rgldev(fov = 30, view_angle = 30)
p
invisible(dev.off())
```
View an interactive version of this plot in the <a href="https://coolbutuseless.github.io/package/devoutrgl/articles/simple-examples.html">online documentation</a>
```{r echo=FALSE, eval=FALSE}
save_animated_scene("man/figures/density.gif")
# system('ffmpeg -i man/figures/density.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" man/figures/density.mp4')
```
<img src="man/figures/density.gif" />
Generating the logo for this package
------------------------------------------------------------------------------
```{r eval = FALSE}
library(ggplot2)
library(dplyr)
hex_df <- tibble(
rad = seq(0, 2*pi, pi/3),
x = sin(rad),
y = cos(rad)
)
p <- ggplot(hex_df) +
geom_polygon(aes(x, y), fill = '#002366', colour = '#436B9530') +
annotate('text', x = 0, y = 0, label = "/dev/out/\n\n\nrgl", size = 20, color = 'grey90') +
coord_fixed() +
theme_minimal(25) +
theme(panel.grid = element_blank())
devoutrgl::rgldev(
width = 5.5,
fov = 30,
view3d_args = list(-45, 0, zoom = 0.8),
dpi = 300,
filename = "man/figures/logo-new.png"
)
p
invisible(dev.off())
```
View an interactive version of this plot in the <a href="https://coolbutuseless.github.io/package/devoutrgl/articles/simple-examples.html">online documentation</a>
<img src="man/figures/logo-new.png" />