Skip to content

Commit 8d71a24

Browse files
committed
adopt use of highlight_unit() in demos where it makes sense
1 parent 0ba1c87 commit 8d71a24

21 files changed

+35
-53
lines changed

R/ggplotly.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
#' ggplotly(viz, tooltip = c("text", "size"))
4848
#'
4949
#' # linked scatterplot brushing
50-
#' library(crosstalk)
51-
#' d <- SharedData$new(mtcars)
50+
#' d <- highlight_unit(mtcars)
5251
#' qplot(data = d, x = mpg, y = wt) %>%
5352
#' subplot(qplot(data = d, x = mpg, y = vs)) %>%
5453
#' layout(title = "Click and drag to select points") %>%
@@ -59,7 +58,7 @@
5958
#' demo("crosstalk-highlight-ggplotly", package = "plotly")
6059
#'
6160
#' # client-side linked brushing in a scatterplot matrix
62-
#' SharedData$new(iris) %>%
61+
#' highlight_unit(iris) %>%
6362
#' GGally::ggpairs(aes(colour = Species), columns = 1:4) %>%
6463
#' ggplotly(tooltip = c("x", "y", "colour")) %>%
6564
#' highlight("plotly_selected")

data-raw/res-us.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ res <- sf::st_read("~/Downloads/tl_2017_us_aiannh/tl_2017_us_aiannh.shp")
99
# (2) crosstalk highlight should set fillcolor...
1010

1111
res %>%
12-
SharedData$new(~NAME) %>%
12+
highlight_unit(~NAME) %>%
1313
plot_ly(text = ~NAME) %>%
1414
highlight(selectize = TRUE, dynamic = TRUE)
1515

demo/animation-tour-USArrests.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ax <- list(
4545
# for nicely formatted slider labels
4646
options(digits = 3)
4747

48-
tour_dat <- crosstalk::SharedData$new(tour_dat, ~state, group = "A")
48+
tour_dat <- highlight_unit(tour_dat, ~state, group = "A")
4949

5050
tour <- proj_dat %>%
5151
plot_ly(x = ~x, y = ~y, frame = ~step, color = I("black")) %>%

demo/crosstalk-filter-dynamic-axis.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ library(tidyr)
33
library(crosstalk)
44

55
m <- gather(mtcars, variable, value, -vs)
6-
msd <- SharedData$new(m, ~variable)
6+
msd <- highlight_unit(m, ~variable)
77
gg <- ggplot(msd, aes(factor(vs), value)) +
88
geom_jitter(alpha = 0.3)
99

demo/crosstalk-filter-lines.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ library(ggplot2)
33
library(gapminder)
44
library(plotly)
55

6-
sd <- SharedData$new(gapminder)
6+
sd <- highlight_unit(gapminder)
77

88
g <- ggplot(sd, aes(year, lifeExp, color = country, group = country)) +
99
geom_line()

demo/crosstalk-highlight-binned-target-a.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# These examples demonstrate ways to display binned/aggregated selections
2-
library(crosstalk)
32
library(plotly)
43

5-
d <- SharedData$new(mpg)
4+
d <- highlight_unit(mpg)
65
dots <- plot_ly(d, colors = "Set1", color = ~class, x = ~displ, y = ~cyl) %>%
76
layout(
87
xaxis = list(title = "Engine displacement"),
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# These examples demonstrate ways to display binned/aggregated selections
2-
library(crosstalk)
32
library(plotly)
43

5-
d <- SharedData$new(mtcars)
4+
d <- highlight_unit(mtcars)
65
sp <- plot_ly(d, x = ~mpg, y = ~disp) %>%
76
add_markers(color = I("black"))
87

9-
# hist/box/violin are all 'statistical trace types' meaning
10-
# they compute aggregations on the fly
8+
# 'statistical trace types'
119
hist <- plot_ly(d, x = ~factor(cyl)) %>%
1210
add_histogram(color = I("black"))
1311
box <- plot_ly(d, y = ~disp, color = I("black")) %>%
@@ -22,7 +20,4 @@ subplot(sp, box, violin, shareY = TRUE, titleX = TRUE, titleY = TRUE) %>%
2220
title = "Click and drag scatterplot",
2321
showlegend = FALSE
2422
) %>%
25-
highlight(
26-
"plotly_selected",
27-
selected = attrs_selected(showlegend = FALSE)
28-
)
23+
highlight("plotly_selected")

demo/crosstalk-highlight-binned-target-c.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# These examples demonstrate ways to display binned/aggregated selections
2-
library(crosstalk)
32
library(plotly)
43

5-
tx <- SharedData$new(txhousing, ~city)
4+
tx <- highlight_unit(txhousing, ~city)
65
p1 <- ggplot(tx, aes(date, median, group = city)) + geom_line() + xlab(NULL)
76
gg1 <- ggplotly(p1, tooltip = c("city", "date", "median"))
87
p2 <- plot_ly(tx, x = ~median, color = I("black")) %>%

demo/crosstalk-highlight-epl-2.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ library(engsoccerdata)
22
library(dplyr)
33
library(tidyr)
44
library(plotly)
5-
library(crosstalk)
65

76
# shape data into desired format
87
dat <- england %>%
@@ -21,7 +20,7 @@ dat <- england %>%
2120
mutate(meanP = mean(cumpts)) %>%
2221
filter(Season > 2006)
2322

24-
sd <- SharedData$new(dat, ~team, "Select a team")
23+
sd <- highlight_unit(dat, ~team, "Select a team")
2524

2625
# a 'wormchart' like fig 8 here http://www.gradaanwr.net/wp-content/uploads/2016/06/dataApr16.pdf
2726
p <- ggplot(sd, aes(x = gameno, y = cumpts - meanP)) +
@@ -33,7 +32,7 @@ p <- ggplot(sd, aes(x = gameno, y = cumpts - meanP)) +
3332
y = "Cumulative points (above/below) average"
3433
)
3534

36-
gg <- ggplotly(p, width = 1050, height = 600, tooltip = "team")
35+
gg <- ggplotly(p, tooltip = "team")
3736

3837
highlight(
3938
gg,

demo/crosstalk-highlight-epl.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ library(engsoccerdata)
22
library(dplyr)
33
library(tidyr)
44
library(plotly)
5-
library(crosstalk)
65

76
# shape data into desired format
87
dat <- england %>%
@@ -17,7 +16,7 @@ dat <- england %>%
1716
group_by(Season, team) %>%
1817
mutate(gameno = row_number(), cumpts = cumsum(pts))
1918

20-
sd <- SharedData$new(dat, ~Season, "Select a season")
19+
sd <- highlight_unit(dat, ~Season, "Select a season")
2120

2221
p <- ggplot(sd, aes(x = gameno, y = cumpts)) +
2322
geom_line(aes(color = Season, group = Season), alpha = 0.5) +

0 commit comments

Comments
 (0)