@@ -16,7 +16,7 @@ add_paths(p)
16
16
add_lines(p )
17
17
```
18
18
19
- ``` {r scatter-intro, echo = FALSE, fig.cap="(ref:scatter-intro)"}
19
+ ``` {r scatter-intro, echo = FALSE, fig.cap="(ref:scatter-intro)", out.extra = 'data-url="/interactives/scatter-intro.html"' }
20
20
knitr::include_graphics("images/scatter-intro.svg")
21
21
```
22
22
@@ -67,7 +67,7 @@ plot_ly() %>%
67
67
layout(xaxis = list (range = c(3 , 8 )))
68
68
```
69
69
70
- ``` {r tooltip-praise, echo = FALSE, fig.cap="(ref:tooltip-praise)"}
70
+ ``` {r tooltip-praise, echo = FALSE, fig.cap="(ref:tooltip-praise)", out.extra = 'data-url="/interactives/tooltip-praise.html"' }
71
71
knitr::include_graphics("images/tooltip-praise.png")
72
72
```
73
73
@@ -83,7 +83,7 @@ If you are new to plotly.js, I recommend taking a bit of time to look through th
83
83
schema()
84
84
```
85
85
86
- ``` {r schema, echo = FALSE, fig.cap="(ref:schema)", out.width = "40%"}
86
+ ``` {r schema, echo = FALSE, fig.cap="(ref:schema)", out.width = "40%", out.extra = 'data-url="/interactives/schema.html"' }
87
87
knitr::include_graphics("images/schema.png")
88
88
```
89
89
@@ -105,9 +105,7 @@ subplot(
105
105
)
106
106
```
107
107
108
-
109
-
110
- ``` {r scatterplots, echo = FALSE, fig.cap = "(ref:scatterplots)"}
108
+ ``` {r scatterplots, echo = FALSE, fig.cap = "(ref:scatterplots)", out.extra = 'data-url="/interactives/scatterplots.html"'}
111
109
knitr::include_graphics("images/scatterplots.svg")
112
110
```
113
111
@@ -124,7 +122,7 @@ subplot(
124
122
)
125
123
```
126
124
127
- ``` {r color-types, echo = FALSE, fig.cap = "(ref:color-types)"}
125
+ ``` {r color-types, echo = FALSE, fig.cap = "(ref:color-types)", out.extra = 'data-url="/interactives/color-types.html"' }
128
126
knitr::include_graphics("images/color-types.svg")
129
127
```
130
128
@@ -144,7 +142,7 @@ subplot(
144
142
) %> % hide_legend()
145
143
```
146
144
147
- ``` {r color-numeric, echo = FALSE, fig.cap = "(ref:color-numeric)"}
145
+ ``` {r color-numeric, echo = FALSE, fig.cap = "(ref:color-numeric)", out.extra = 'data-url="/interactives/color-numeric.html"' }
148
146
knitr::include_graphics("images/color-numeric.svg")
149
147
```
150
148
@@ -159,7 +157,7 @@ subplot(
159
157
) %> % hide_legend()
160
158
```
161
159
162
- ``` {r color-discrete, echo = FALSE, fig.cap = "(ref:color-discrete)"}
160
+ ``` {r color-discrete, echo = FALSE, fig.cap = "(ref:color-discrete)", out.extra = 'data-url="/interactives/color-discrete.html"' }
163
161
knitr::include_graphics("images/color-discrete.svg")
164
162
```
165
163
@@ -169,7 +167,7 @@ As introduced in Figure \@ref(fig:intro-range), color codes can be specified man
169
167
add_markers(p , color = I(" black" ))
170
168
```
171
169
172
- ``` {r color-manual, echo = FALSE, fig.cap = "(ref:color-manual)"}
170
+ ``` {r color-manual, echo = FALSE, fig.cap = "(ref:color-manual)", out.extra = 'data-url="/interactives/color-manual.html"' }
173
171
knitr::include_graphics("images/color-manual.svg")
174
172
```
175
173
@@ -194,7 +192,7 @@ subplot(
194
192
)
195
193
```
196
194
197
- ``` {r symbol-factor, echo = FALSE, fig.cap = "(ref:symbol-factor)"}
195
+ ``` {r symbol-factor, echo = FALSE, fig.cap = "(ref:symbol-factor)", out.extra = 'data-url="/interactives/symbol-factor.html"' }
198
196
knitr::include_graphics("images/symbol-factor.svg")
199
197
```
200
198
@@ -210,7 +208,7 @@ subplot(
210
208
)
211
209
```
212
210
213
- ``` {r symbol-factor-range, echo = FALSE, fig.cap = "(ref:symbol-factor-range)"}
211
+ ``` {r symbol-factor-range, echo = FALSE, fig.cap = "(ref:symbol-factor-range)", out.extra = 'data-url="/interactives/symbol-factor-range.html"' }
214
212
knitr::include_graphics("images/symbol-factor-range.svg")
215
213
```
216
214
@@ -221,7 +219,7 @@ plot_ly(mpg, x = ~cty, y = ~hwy) %>%
221
219
add_markers(symbol = I(18 ), alpha = 0.5 )
222
220
```
223
221
224
- ``` {r symbol-factor-manual, echo = FALSE, fig.cap = "(ref:symbol-factor-manual)"}
222
+ ``` {r symbol-factor-manual, echo = FALSE, fig.cap = "(ref:symbol-factor-manual)", out.extra = 'data-url="/interactives/symbol-factor-manual.html"' }
225
223
knitr::include_graphics("images/symbol-factor-manual.svg")
226
224
```
227
225
@@ -236,8 +234,8 @@ plot_ly(mpg, x = ~cty, y = ~hwy) %>%
236
234
add_markers(symbol = I(18 ), alpha = 0.5 , stroke = I(" black" ), span = I(1 ))
237
235
```
238
236
239
- ``` {r stroke-manual, echo = FALSE, fig.cap = "(ref:stroke-manual)"}
240
- knitr::include_graphics("images/symbol-factor-range .svg")
237
+ ``` {r stroke-manual, echo = FALSE, fig.cap = "(ref:stroke-manual)", out.extra = 'data-url="/interactives/stroke-manual.html"' }
238
+ knitr::include_graphics("images/symbol-manual .svg")
241
239
```
242
240
243
241
### Size {#marker-size}
@@ -252,17 +250,17 @@ subplot(
252
250
)
253
251
```
254
252
255
- ``` {r sizes, echo = FALSE, fig.cap = "(ref:sizes)"}
253
+ ``` {r sizes, echo = FALSE, fig.cap = "(ref:sizes)", out.extra = 'data-url="/interactives/sizes.html"' }
256
254
knitr::include_graphics("images/sizes.svg")
257
255
```
258
256
259
257
Similar to other arguments, ` I() ` can be used to specify the size directly. In the case of markers, ` size ` controls the [ ` marker.size ` ] ( https://plot.ly/r/reference/#scatter-marker-size ) plotly.js attribute. Remember, you always have the option to set this attribute directly by doing something similar to Figure \@ ref(fig: sizes-manual ).
260
258
261
259
``` r
262
- plot_ly(mpg , x = ~ cty , y = ~ hwy , alpha = 0.3 , marker = list ( size = 10 ))
260
+ plot_ly(mpg , x = ~ cty , y = ~ hwy , alpha = 0.3 , size = I( 30 ))
263
261
```
264
262
265
- ``` {r sizes-manual, echo = FALSE, fig.cap = "(ref:sizes-manual)"}
263
+ ``` {r sizes-manual, echo = FALSE, fig.cap = "(ref:sizes-manual)", out.extra = 'data-url="/interactives/sizes-manual.html"' }
266
264
knitr::include_graphics("images/sizes-manual.svg")
267
265
```
268
266
@@ -274,17 +272,14 @@ A dotplot is similar to a scatterplot, except instead of two numeric axes, one i
274
272
A popular application for dotplots (with error bars) is the so-called "coefficient plot" for visualizing the point estimates of coefficients and their standard error. The ` coefplot() ` function in the ** coefplot** package [ @coefplot ] and the ` ggcoef() ` function in the ** GGally** both produce coefficient plots for many types of model objects in R using ** ggplot2** , which we can translate to plotly via ` ggplotly() ` . Since these packages use points and segments to draw the coefficient plots, the hover information is not the best, and it'd be better to use [ error objects] ( https://plot.ly/r/reference/#scatter-error_x ) . Figure \@ ref(fig: coefplot ) uses the ` tidy() ` function from the ** broom** package [ @broom ] to obtain a data frame with one row per model coefficient, and produce a coefficient plot with error bars along the x-axis.
275
273
276
274
``` r
277
- library(broom )
278
- library(forcats )
279
-
280
275
# Fit a full-factorial linear model
281
276
m <- lm(Sepal.Length ~ Sepal.Width * Petal.Length * Petal.Width , data = iris )
282
277
283
278
# (1) get a tidy() data structure of covariate-level info (e.g., point estimate, standard error, etc)
284
279
# (2) make sure term column is a factor ordered by the estimate
285
280
# (3) plot estimate by term with an error bar for the standard error
286
- tidy(m ) %> %
287
- mutate(term = fct_reorder(term , estimate )) %> %
281
+ broom :: tidy(m ) %> %
282
+ mutate(term = forcats :: fct_reorder(term , estimate )) %> %
288
283
plot_ly(x = ~ estimate , y = ~ term ) %> %
289
284
add_markers(
290
285
error_x = ~ list (value = std.error ),
@@ -293,7 +288,7 @@ tidy(m) %>%
293
288
)
294
289
```
295
290
296
- ``` {r coefplot, echo = FALSE, fig.cap = "(ref:coefplot)"}
291
+ ``` {r coefplot, echo = FALSE, fig.cap = "(ref:coefplot)", , out.extra = 'data-url="/interactives/coefplot.html"' }
297
292
knitr::include_graphics("images/coefplot.png")
298
293
```
299
294
@@ -319,7 +314,7 @@ plot_ly(tx5, x = ~date, y = ~median) %>%
319
314
add_lines(linetype = ~ city )
320
315
```
321
316
322
- ``` {r linetypes, echo = FALSE, fig.cap = "(ref:linetypes)"}
317
+ ``` {r linetypes, echo = FALSE, fig.cap = "(ref:linetypes)", out.extra = 'data-url="/interactives/linetypes.html"' }
323
318
knitr::include_graphics("images/linetypes.svg")
324
319
```
325
320
@@ -338,7 +333,7 @@ plot_ly(tx5, x = ~date, y = ~median) %>%
338
333
add_lines(linetype = ~ city , linetypes = ltys )
339
334
```
340
335
341
- ``` {r linetypes-manual, echo = FALSE, fig.cap = "(ref:linetypes-manual)"}
336
+ ``` {r linetypes-manual, echo = FALSE, fig.cap = "(ref:linetypes-manual)", out.extra = 'data-url="/interactives/linetypes-manual.html"' }
342
337
knitr::include_graphics("images/linetypes-manual.svg")
343
338
```
344
339
@@ -425,7 +420,7 @@ mpg %>%
425
420
layout(xaxis = list (title = " Miles per gallon" ))
426
421
```
427
422
428
- ``` {r dumbell, echo = FALSE, fig.cap = "(ref:dumbell)"}
423
+ ``` {r dumbell, echo = FALSE, fig.cap = "(ref:dumbell)", out.extra = 'data-url="/interactives/dumbell.html"' }
429
424
knitr::include_graphics("images/dumbell.svg")
430
425
```
431
426
@@ -450,7 +445,7 @@ plot_ly(dat, x = ~date, xend = ~date, color = ~Close > Open,
450
445
rangeslider()
451
446
```
452
447
453
- ``` {r candlestick, echo = FALSE, fig.cap = "(ref:candlestick)"}
448
+ ``` {r candlestick, echo = FALSE, fig.cap = "(ref:candlestick)", out.extra = 'data-url="/interactives/candlestick.html"' }
454
449
knitr::include_graphics("images/candlestick.svg")
455
450
```
456
451
@@ -469,7 +464,7 @@ for (k in kerns) {
469
464
p
470
465
```
471
466
472
- ``` {r densities, echo = FALSE, fig.cap = "(ref:densities)"}
467
+ ``` {r densities, echo = FALSE, fig.cap = "(ref:densities)", out.extra = 'data-url="/interactives/densities.html"' }
473
468
knitr::include_graphics("images/densities.svg")
474
469
```
475
470
@@ -508,7 +503,7 @@ subplot(
508
503
) %> % hide_legend()
509
504
```
510
505
511
- ``` {r pcp-common, echo = FALSE, fig.cap = "(ref:pcp-common)"}
506
+ ``` {r pcp-common, echo = FALSE, fig.cap = "(ref:pcp-common)", out.extra = 'data-url="/interactives/pcp-common.html"' }
512
507
knitr::include_graphics("images/pcp-common.svg")
513
508
```
514
509
@@ -531,7 +526,7 @@ base %>%
531
526
color = I(" red" ), data = maps :: canada.cities )
532
527
```
533
528
534
- ``` {r map-canada, echo = FALSE, fig.cap = "(ref:map-canada)"}
529
+ ``` {r map-canada, echo = FALSE, fig.cap = "(ref:map-canada)", out.extra = 'data-url="/interactives/map-canada.html"' }
535
530
knitr::include_graphics("images/map-canada.png")
536
531
```
537
532
@@ -541,7 +536,7 @@ As discussion surrounding Figure \@ref(fig:split-color) points out, scatter-base
541
536
add_polygons(base , split = ~ subregion , hoveron = " fills" )
542
537
```
543
538
544
- ``` {r map-canada-split, echo = FALSE, fig.cap = "(ref:map-canada-split)"}
539
+ ``` {r map-canada-split, echo = FALSE, fig.cap = "(ref:map-canada-split)", out.extra = 'data-url="/interactives/map-canada-split.html"' }
545
540
knitr::include_graphics("images/map-canada-split.png")
546
541
```
547
542
@@ -559,6 +554,6 @@ broom::augment(m) %>%
559
554
add_lines(y = ~ .fitted , color = I(" steelblue" ))
560
555
```
561
556
562
- ``` {r broom-lm, echo = FALSE, fig.cap = "(ref:broom-lm)"}
557
+ ``` {r broom-lm, echo = FALSE, fig.cap = "(ref:broom-lm)", out.extra = 'data-url="/interactives/broom-lm.html"' }
563
558
knitr::include_graphics("images/broom-lm.svg")
564
559
```
0 commit comments