Skip to content

Commit 6561a64

Browse files
committed
small tweaks; bit.ly links; links to interactives
1 parent 231268c commit 6561a64

File tree

204 files changed

+121167
-972
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+121167
-972
lines changed

DESCRIPTION

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Title: This is not really an R package, but this is here to list the dependencie
33
Version: 0.1
44
Authors@R: person("Carson", "Sievert", email = "[email protected]",
55
role = c("aut", "cre"))
6-
Depends: R (>= 3.1.0)
76
URL: https://github.com/cpsievert/plotly_book
8-
Imports:
7+
Depends:
8+
R (>= 3.1.0),
99
tidyverse,
1010
shiny,
1111
plotly,
@@ -35,13 +35,14 @@ Imports:
3535
leaflet,
3636
colorspace,
3737
idbr,
38-
emo
38+
emo,
39+
slopegraph
3940
SystemRequirements: pandoc (>= 1.12.3) - http://johnmacfarlane.net/pandoc
4041
Remotes:
41-
ropensci/plotly,
4242
ramnathv/htmlwidgets,
4343
react-R/reactR,
4444
yihui/knitr#1650,
4545
hadley/ggstat,
4646
hadley/emo,
47-
hrbrmstr/albersusa
47+
hrbrmstr/albersusa,
48+
leeper/slopegraph

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
gitbook:
22
mkdir -p docs/images && cp images/* docs/images
3+
mkdir -p docs/interactives && cp -r interactives/* docs/interactives
34
Rscript --quiet _render.R "bookdown::gitbook"
45
cp _redirects docs/
56

_output.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ bookdown::gitbook:
1313
after_body:
1414
- includes/rstudio-cloud.html
1515
- includes/ga.html
16+
- includes/data-url.html
1617

1718
bookdown::html_chapters:
1819
css: [css/style.css, css/toc.css]

creating-overview.Rmd

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ plot_ly(diamonds, x = ~cut, y = ~clarity)
2828
plot_ly(diamonds, x = ~cut, color = ~clarity, colors = "Accent")
2929
```
3030

31-
```{r intro-defaults, echo = FALSE, fig.cap = "(ref:intro-defaults)"}
31+
```{r intro-defaults, echo = FALSE, fig.cap = "(ref:intro-defaults)", fig.link = "/interactives/intro-defaults.html"}
3232
knitr::include_graphics("images/intro-defaults.svg")
3333
```
3434

@@ -47,7 +47,7 @@ plot_ly(diamonds, x = ~cut, color = "black")
4747
plot_ly(diamonds, x = ~cut, color = I("red"), stroke = I("black"), span = I(2))
4848
```
4949

50-
```{r intro-range, echo = FALSE, fig.cap = "(ref:intro-range)"}
50+
```{r intro-range, echo = FALSE, fig.cap = "(ref:intro-range)", fig.link = "/interactives/intro-range.html"}
5151
knitr::include_graphics("images/intro-range.svg")
5252
```
5353

@@ -114,7 +114,7 @@ diamonds %>%
114114
)
115115
```
116116

117-
```{r intro-dplyr, echo = FALSE, fig.cap = "(ref:intro-dplyr)"}
117+
```{r intro-dplyr, echo = FALSE, fig.cap = "(ref:intro-dplyr)", fig.link = "/interactives/intro-dplyr.html"}
118118
knitr::include_graphics("images/intro-dplyr.png")
119119
```
120120

@@ -146,9 +146,7 @@ p <- plot_ly(diamonds, x = ~cut, color = ~clarity, colors = "Accent")
146146
plotly_json(p)
147147
```
148148

149-
150-
151-
```{r intro-json, echo = FALSE, fig.cap = "(ref:intro-json)", out.width="70%"}
149+
```{r intro-json, echo = FALSE, fig.cap = "(ref:intro-json)", out.width="70%", fig.link = "/interactives/intro-json.html"}
152150
knitr::include_graphics("images/intro-json.png")
153151
```
154152

@@ -193,7 +191,7 @@ p <- ggplot(diamonds, aes(x = log(carat), y = log(price))) +
193191
ggplotly(p)
194192
```
195193

196-
```{r hexbin, echo = FALSE, fig.cap = "(ref:hexbin)"}
194+
```{r hexbin, echo = FALSE, fig.cap = "(ref:hexbin)", fig.link = "/interactives/hexbin.html"}
197195
knitr::include_graphics("images/hexbin.png")
198196
```
199197

creating-scatter.Rmd

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ add_paths(p)
1616
add_lines(p)
1717
```
1818

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"'}
2020
knitr::include_graphics("images/scatter-intro.svg")
2121
```
2222

@@ -67,7 +67,7 @@ plot_ly() %>%
6767
layout(xaxis = list(range = c(3, 8)))
6868
```
6969

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"'}
7171
knitr::include_graphics("images/tooltip-praise.png")
7272
```
7373

@@ -83,7 +83,7 @@ If you are new to plotly.js, I recommend taking a bit of time to look through th
8383
schema()
8484
```
8585

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"'}
8787
knitr::include_graphics("images/schema.png")
8888
```
8989

@@ -105,9 +105,7 @@ subplot(
105105
)
106106
```
107107

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"'}
111109
knitr::include_graphics("images/scatterplots.svg")
112110
```
113111

@@ -124,7 +122,7 @@ subplot(
124122
)
125123
```
126124

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"'}
128126
knitr::include_graphics("images/color-types.svg")
129127
```
130128

@@ -144,7 +142,7 @@ subplot(
144142
) %>% hide_legend()
145143
```
146144

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"'}
148146
knitr::include_graphics("images/color-numeric.svg")
149147
```
150148

@@ -159,7 +157,7 @@ subplot(
159157
) %>% hide_legend()
160158
```
161159

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"'}
163161
knitr::include_graphics("images/color-discrete.svg")
164162
```
165163

@@ -169,7 +167,7 @@ As introduced in Figure \@ref(fig:intro-range), color codes can be specified man
169167
add_markers(p, color = I("black"))
170168
```
171169

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"'}
173171
knitr::include_graphics("images/color-manual.svg")
174172
```
175173

@@ -194,7 +192,7 @@ subplot(
194192
)
195193
```
196194

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"'}
198196
knitr::include_graphics("images/symbol-factor.svg")
199197
```
200198

@@ -210,7 +208,7 @@ subplot(
210208
)
211209
```
212210

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"'}
214212
knitr::include_graphics("images/symbol-factor-range.svg")
215213
```
216214

@@ -221,7 +219,7 @@ plot_ly(mpg, x = ~cty, y = ~hwy) %>%
221219
add_markers(symbol = I(18), alpha = 0.5)
222220
```
223221

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"'}
225223
knitr::include_graphics("images/symbol-factor-manual.svg")
226224
```
227225

@@ -236,8 +234,8 @@ plot_ly(mpg, x = ~cty, y = ~hwy) %>%
236234
add_markers(symbol = I(18), alpha = 0.5, stroke = I("black"), span = I(1))
237235
```
238236

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")
241239
```
242240

243241
### Size {#marker-size}
@@ -252,17 +250,17 @@ subplot(
252250
)
253251
```
254252

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"'}
256254
knitr::include_graphics("images/sizes.svg")
257255
```
258256

259257
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).
260258

261259
```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))
263261
```
264262

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"'}
266264
knitr::include_graphics("images/sizes-manual.svg")
267265
```
268266

@@ -274,17 +272,14 @@ A dotplot is similar to a scatterplot, except instead of two numeric axes, one i
274272
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.
275273

276274
```r
277-
library(broom)
278-
library(forcats)
279-
280275
# Fit a full-factorial linear model
281276
m <- lm(Sepal.Length ~ Sepal.Width * Petal.Length * Petal.Width, data = iris)
282277

283278
# (1) get a tidy() data structure of covariate-level info (e.g., point estimate, standard error, etc)
284279
# (2) make sure term column is a factor ordered by the estimate
285280
# (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)) %>%
288283
plot_ly(x = ~estimate, y = ~term) %>%
289284
add_markers(
290285
error_x = ~list(value = std.error),
@@ -293,7 +288,7 @@ tidy(m) %>%
293288
)
294289
```
295290

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"'}
297292
knitr::include_graphics("images/coefplot.png")
298293
```
299294

@@ -319,7 +314,7 @@ plot_ly(tx5, x = ~date, y = ~median) %>%
319314
add_lines(linetype = ~city)
320315
```
321316

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"'}
323318
knitr::include_graphics("images/linetypes.svg")
324319
```
325320

@@ -338,7 +333,7 @@ plot_ly(tx5, x = ~date, y = ~median) %>%
338333
add_lines(linetype = ~city, linetypes = ltys)
339334
```
340335

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"'}
342337
knitr::include_graphics("images/linetypes-manual.svg")
343338
```
344339

@@ -425,7 +420,7 @@ mpg %>%
425420
layout(xaxis = list(title = "Miles per gallon"))
426421
```
427422

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"'}
429424
knitr::include_graphics("images/dumbell.svg")
430425
```
431426

@@ -450,7 +445,7 @@ plot_ly(dat, x = ~date, xend = ~date, color = ~Close > Open,
450445
rangeslider()
451446
```
452447

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"'}
454449
knitr::include_graphics("images/candlestick.svg")
455450
```
456451

@@ -469,7 +464,7 @@ for (k in kerns) {
469464
p
470465
```
471466

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"'}
473468
knitr::include_graphics("images/densities.svg")
474469
```
475470

@@ -508,7 +503,7 @@ subplot(
508503
) %>% hide_legend()
509504
```
510505

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"'}
512507
knitr::include_graphics("images/pcp-common.svg")
513508
```
514509

@@ -531,7 +526,7 @@ base %>%
531526
color = I("red"), data = maps::canada.cities)
532527
```
533528

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"'}
535530
knitr::include_graphics("images/map-canada.png")
536531
```
537532

@@ -541,7 +536,7 @@ As discussion surrounding Figure \@ref(fig:split-color) points out, scatter-base
541536
add_polygons(base, split = ~subregion, hoveron = "fills")
542537
```
543538

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"'}
545540
knitr::include_graphics("images/map-canada-split.png")
546541
```
547542

@@ -559,6 +554,6 @@ broom::augment(m) %>%
559554
add_lines(y = ~.fitted, color = I("steelblue"))
560555
```
561556

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"'}
563558
knitr::include_graphics("images/broom-lm.svg")
564559
```

0 commit comments

Comments
 (0)