Skip to content

Commit 5e5db59

Browse files
authored
Replace iris with penguins in examples and tests (#1830)
* Replace iris examples with palmerpenguins * Fix duplicate line * Re-generate documentation * Replaces iris with penguin in tests
1 parent e053059 commit 5e5db59

14 files changed

+107
-96
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ Suggests:
7474
processx,
7575
plotlyGeoAssets,
7676
forcats,
77-
thematic
77+
thematic,
78+
palmerpenguins
7879
LazyData: true
7980
RoxygenNote: 7.1.1
8081
Encoding: UTF-8

R/ggplotly.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
#' @seealso [plot_ly()]
3737
#' @examples \dontrun{
3838
#' # simple example
39-
#' ggiris <- qplot(Petal.Width, Sepal.Length, data = iris, color = Species)
40-
#' ggplotly(ggiris)
39+
#' ggpenguins <- qplot(bill_length_mm , body_mass_g,
40+
#' data = palmerpenguins::penguins, color = species)
41+
#' ggplotly(ggpenguins)
4142
#'
4243
#' data(canada.cities, package = "maps")
4344
#' viz <- ggplot(canada.cities, aes(long, lat)) +
@@ -58,7 +59,7 @@
5859
#' demo("crosstalk-highlight-ggplotly", package = "plotly")
5960
#'
6061
#' # client-side linked brushing in a scatterplot matrix
61-
#' highlight_key(iris) %>%
62+
#' highlight_key(palmerpenguins::penguins) %>%
6263
#' GGally::ggpairs(aes(colour = Species), columns = 1:4) %>%
6364
#' ggplotly(tooltip = c("x", "y", "colour")) %>%
6465
#' highlight("plotly_selected")

R/plotly.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@
118118
#' # You might notice plot_ly() has named arguments that aren't in this figure
119119
#' # reference. These arguments make it easier to map abstract data values to
120120
#' # visual attributes.
121-
#' p <- plot_ly(iris, x = ~Sepal.Width, y = ~Sepal.Length)
122-
#' add_markers(p, color = ~Petal.Length, size = ~Petal.Length)
123-
#' add_markers(p, color = ~Species)
124-
#' add_markers(p, color = ~Species, colors = "Set1")
125-
#' add_markers(p, symbol = ~Species)
126-
#' add_paths(p, linetype = ~Species)
121+
#' p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~body_mass_g)
122+
#' add_markers(p, color = ~bill_depth_mm, size = ~bill_depth_mm)
123+
#' add_markers(p, color = ~species)
124+
#' add_markers(p, color = ~species, colors = "Set1")
125+
#' add_markers(p, symbol = ~species)
126+
#' add_paths(p, linetype = ~species)
127127
#'
128128
#' }
129129
#'

man/ggplotly.Rd

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plot_ly.Rd

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-api.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ test_that("Can overwrite a grid", {
9393

9494
id <- new_id()
9595
m <- api_create(mtcars, id)
96-
m2 <- api_create(iris, id)
96+
m2 <- api_create(palmerpenguins::penguins, id)
9797
expect_true(identical(m$embed_url, m2$embed_url))
9898
expect_false(identical(m$cols, m2$cols))
9999
})

tests/testthat/test-ggplot-labels.R

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
context("labels")
22

33
test_that("ggtitle is translated correctly", {
4-
ggiris <- ggplot(iris) +
5-
geom_point(aes(Petal.Width, Sepal.Width)) +
4+
ggpenguin <- ggplot(palmerpenguins::penguins) +
5+
geom_point(aes(bill_length_mm, bill_depth_mm)) +
66
ggtitle("My amazing plot!")
7-
info <- expect_doppelganger_built(ggiris, "labels-ggtitle")
7+
info <- expect_doppelganger_built(ggpenguin, "labels-ggtitle")
88
expect_identical(info$layout$title$text, "My amazing plot!")
99
})
1010

1111
test_that("ylab is translated correctly", {
12-
ggiris <- ggplot(iris) +
13-
geom_point(aes(Petal.Width, Sepal.Width)) +
14-
ylab("sepal width")
15-
info <- expect_doppelganger_built(ggiris, "labels-ylab")
12+
ggpenguin <- ggplot(palmerpenguins::penguins) +
13+
geom_point(aes(bill_length_mm, bill_depth_mm)) +
14+
ylab("bill depth")
15+
info <- expect_doppelganger_built(ggpenguin, "labels-ylab")
1616
labs <- c(info$layout$xaxis$title$text, info$layout$yaxis$title$text)
17-
expect_identical(labs, c("Petal.Width", "sepal width"))
17+
expect_identical(labs, c("bill_length_mm", "bill depth"))
1818
})
1919

2020
test_that("scale_x_continuous(name) is translated correctly", {
21-
ggiris <- ggplot(iris) +
22-
geom_point(aes(Petal.Width, Sepal.Width)) +
23-
scale_x_continuous("petal width")
24-
info <- expect_doppelganger_built(ggiris, "labels-scale_x_continuous_name")
21+
ggpenguin <- ggplot(palmerpenguins::penguins) +
22+
geom_point(aes(bill_length_mm, bill_depth_mm)) +
23+
scale_x_continuous("bill length")
24+
info <- expect_doppelganger_built(ggpenguin, "labels-scale_x_continuous_name")
2525
labs <- c(info$layout$xaxis$title$text, info$layout$yaxis$title$text)
26-
expect_identical(labs, c("petal width", "Sepal.Width"))
26+
expect_identical(labs, c("bill length", "bill_depth_mm"))
2727
})
2828

2929
test_that("angled ticks are translated correctly", {
30-
ggiris <- ggplot(iris) +
31-
geom_point(aes(Petal.Width, Sepal.Width)) +
30+
ggpenguin <- ggplot(palmerpenguins::penguins) +
31+
geom_point(aes(bill_length_mm, bill_depth_mm)) +
3232
theme(axis.text.x = element_text(angle = 45))
33-
info <- expect_doppelganger_built(ggiris, "labels-angles")
33+
info <- expect_doppelganger_built(ggpenguin, "labels-angles")
3434
expect_identical(info$layout$xaxis$tickangle, -45)
3535
})
3636

3737
test_that("xaxis/yaxis automargin defaults to TRUE", {
38-
p <- ggplot(iris, aes(Species)) + geom_bar() + coord_flip()
38+
p <- ggplot(palmerpenguins::penguins, aes(species)) + geom_bar() + coord_flip()
3939
l <- plotly_build(p)$x
4040
expect_true(l$layout$xaxis$automargin)
4141
expect_true(l$layout$yaxis$automargin)
@@ -49,7 +49,8 @@ test_that("factor labels work", {
4949
})
5050

5151
test_that("empty labels work", {
52-
p <- ggplot(iris, aes(Petal.Length, Sepal.Width, color = Species)) +
52+
p <- ggplot(palmerpenguins::penguins,
53+
aes(bill_length_mm, bill_depth_mm, color = species)) +
5354
geom_point() +
5455
labs(x = element_blank(), y = element_blank())
5556
b <- expect_doppelganger_built(p, "labs-element-blank")

tests/testthat/test-ggplot-legend.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ test_that("very long legend items", {
7272
info <- expect_traces(p_long_items, 3, "very-long-legend-items")
7373
})
7474

75-
iris$All <- "All species"
76-
p <- qplot(data = iris, x = Sepal.Length, y = Sepal.Width, color = All)
75+
penguins <- palmerpenguins::penguins
76+
penguins$All <- "All species"
77+
p <- qplot(data = penguins, x = bill_length_mm, y = bill_depth_mm, color = All)
7778

7879
test_that("legend is created with discrete mapping regardless of unique values", {
7980
info <- expect_traces(p, 1, "one-entry")

tests/testthat/test-ggplot-size.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
context("size")
22

33
test_that("size is a vector if it is specified", {
4-
iplot <- ggplot(iris) +
5-
geom_point(aes(Petal.Width, Sepal.Width, size=Petal.Length))
6-
L <- expect_doppelganger_built(iplot, "size-is-a-vector")
4+
pplot <- ggplot(palmerpenguins::penguins) +
5+
geom_point(aes(bill_length_mm, bill_depth_mm, size=flipper_length_mm))
6+
L <- expect_doppelganger_built(pplot, "size-is-a-vector")
77
m <- L$data[[1]]$marker
88
expect_that(m, is_a("list"))
99
expect_true(length(m$size) > 1)

tests/testthat/test-ggplot-theme.R

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
context("ggplot themes")
22

3-
iris.base <- ggplot(iris) +
4-
geom_point(aes(Petal.Width, Sepal.Width)) +
3+
penguin.base <- ggplot(palmerpenguins::penguins) +
4+
geom_point(aes(bill_length_mm, bill_length_mm)) +
55
theme_grey()
66

77
test_that("background translated correctly",{
8-
ggiris <- iris.base +
8+
ggpenguin <- penguin.base +
99
theme(panel.background = element_rect(fill = "blue"),
1010
plot.background = element_rect(fill = "green"))
11-
info <- expect_doppelganger_built(ggiris, "theme-background")
11+
info <- expect_doppelganger_built(ggpenguin, "theme-background")
1212
L <- info$layout
1313
expect_true(L$plot_bgcolor == toRGB("blue"))
1414
expect_true(L$paper_bgcolor == toRGB("green"))
1515
})
1616

1717
test_that("grid/ticks translated correctly",{
18-
ggiris <- iris.base +
18+
ggpenguin <- penguin.base +
1919
theme(axis.ticks = element_line(colour = "red"),
2020
panel.grid.major = element_line(colour = "violet"))
21-
info <- expect_doppelganger_built(ggiris, "theme-ticks-and-grids")
21+
info <- expect_doppelganger_built(ggpenguin, "theme-ticks-and-grids")
2222
for (xy in c("x", "y")) {
2323
ax.list <- info$layout[[paste0(xy, "axis")]]
2424
expect_true(ax.list$tickcolor == toRGB("red"))
@@ -27,17 +27,17 @@ test_that("grid/ticks translated correctly",{
2727
})
2828

2929
test_that("show ticks as 'outside' by default", {
30-
ggiris <- iris.base
31-
info <- expect_doppelganger_built(ggiris, "theme-ticks-default")
30+
ggpenguin <- penguin.base
31+
info <- expect_doppelganger_built(ggpenguin, "theme-ticks-default")
3232
for (xy in c("x", "y")) {
3333
ax.list <- info$layout[[paste0(xy, "axis")]]
3434
expect_identical(ax.list$ticks, "outside")
3535
}
3636
})
3737

3838
test_that("do not show zeroline by default", {
39-
ggiris <- iris.base
40-
info <- expect_doppelganger_built(ggiris, "theme-zeroline-default")
39+
ggpenguin <- penguin.base
40+
info <- expect_doppelganger_built(ggpenguin, "theme-zeroline-default")
4141
for (xy in c("x", "y")) {
4242
ax.list <- info$layout[[paste0(xy, "axis")]]
4343
expect_identical(ax.list$zeroline, FALSE)
@@ -63,12 +63,12 @@ test_that("marker default shape is a circle", {
6363
})
6464

6565
test_that("plot panel border is translated correctly", {
66-
ggiris <- iris.base + theme_grey() # has no panel.border
67-
info <- expect_doppelganger_built(ggiris, "theme-panel-border-1")
66+
ggpenguin <- penguin.base + theme_grey() # has no panel.border
67+
info <- expect_doppelganger_built(ggpenguin, "theme-panel-border-1")
6868

69-
red <- ggplot(iris) +
69+
red <- ggplot(palmerpenguins::penguins) +
7070
theme_grey() +
71-
geom_point(aes(Petal.Width, Sepal.Width)) +
71+
geom_point(aes(bill_length_mm, bill_depth_mm)) +
7272
theme(panel.border = element_rect(colour = "red", fill = NA))
7373

7474
info <- expect_doppelganger_built(red, "theme-panel-border-2")

tests/testthat/test-plotly-color.R

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ expect_traces <- function(p, n.traces, name){
88
}
99

1010
test_that("plot_ly() handles a simple scatterplot", {
11-
p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Petal.Width)
11+
p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_length_mm, color = ~bill_depth_mm)
1212
})
1313

1414
test_that("Mapping a factor variable to color works", {
15-
p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Species)
15+
p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_length_mm, color = ~species)
1616
l <- expect_traces(p, 3, "scatterplot-color-factor")
1717
markers <- lapply(l$data, "[[", "marker")
1818
cols <- unlist(lapply(markers, "[[", "color"))
@@ -24,15 +24,15 @@ test_that("Custom RColorBrewer pallette works for factor variable", {
2424
# convert hex to rgba spec for comparison's sake
2525
colsToCompare <- toRGB(cols)
2626
# specifying a pallette set should "span the gamut"
27-
p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Species,
27+
p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_length_mm, color = ~species,
2828
colors = "Set1")
2929
l <- expect_traces(p, 3, "scatterplot-color-factor-custom")
3030
markers <- lapply(l$data, "[[", "marker")
3131
colz <- unlist(lapply(markers, "[[", "color"))
3232
idx <- if (packageVersion("scales") > '1.0.0') c(1, 2, 3) else c(1, 5, 9)
3333
expect_identical(sort(colsToCompare[idx]), sort(colz))
3434
# providing vector of RGB codes should also work
35-
p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Species,
35+
p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_length_mm, color = ~species,
3636
colors = cols[1:3])
3737
l <- expect_traces(p, 3, "scatterplot-color-factor-custom2")
3838
markers <- lapply(l$data, "[[", "marker")
@@ -51,16 +51,16 @@ test_that("Passing hex codes to colors argument works", {
5151
})
5252

5353
test_that("Mapping a numeric variable to color works", {
54-
p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Petal.Width)
54+
p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_length_mm, color = ~bill_depth_mm)
5555
# one trace is for the colorbar
5656
l <- expect_traces(p, 2, "scatterplot-color-numeric")
5757
idx <- vapply(l$data, is.colorbar, logical(1))
5858
markerScale <- l$data[[which(idx)]]$marker
5959
markerDat <- l$data[[which(!idx)]]$marker
60-
expect_true(all(markerDat$color == iris$Petal.Width))
61-
expect_true(markerScale$colorbar$title == "Petal.Width")
62-
expect_true(min(iris$Petal.Width) == markerScale$cmin)
63-
expect_true(max(iris$Petal.Width) == markerScale$cmax)
60+
expect_true(all(markerDat$color == na.omit(palmerpenguins::penguins$bill_depth_mm)))
61+
expect_true(markerScale$colorbar$title == "bill_depth_mm")
62+
expect_true(min(na.omit(palmerpenguins::penguins$bill_depth_mm)) == markerScale$cmin)
63+
expect_true(max(na.omit(palmerpenguins::penguins$bill_depth_mm)) == markerScale$cmax)
6464
expect_true(all(0 <= markerScale$colorscale[,1] & markerScale$colorscale[,1] <= 1))
6565
})
6666

@@ -76,20 +76,20 @@ test_that("color/stroke mapping with box translates correctly", {
7676
})
7777

7878
test_that("Custom RColorBrewer pallette works for numeric variable", {
79-
p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length,
80-
color = ~Petal.Width, colors = "Greens")
79+
p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_length_mm,
80+
color = ~bill_depth_mm, colors = "Greens")
8181
# one trace is for the colorbar
8282
l <- expect_traces(p, 2, "scatterplot-color-numeric-custom")
8383
})
8484

8585
test_that("axis titles get attached to scene object for 3D plots", {
86-
p <- plot_ly(iris, x = ~Petal.Length, y = ~Petal.Width, z = ~Sepal.Width)
86+
p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_depth_mm, z = ~flipper_length_mm)
8787
l <- expect_traces(p, 1, "scatterplot-scatter3d-axes")
8888
expect_identical(l$data[[1]]$type, "scatter3d")
8989
scene <- l$layout$scene
90-
expect_true(scene$xaxis$title == "Petal.Length")
91-
expect_true(scene$yaxis$title == "Petal.Width")
92-
expect_true(scene$zaxis$title == "Sepal.Width")
90+
expect_true(scene$xaxis$title == "bill_length_mm")
91+
expect_true(scene$yaxis$title == "bill_depth_mm")
92+
expect_true(scene$zaxis$title == "flipper_length_mm")
9393
})
9494

9595
test_that("Can specify a scale manually", {

tests/testthat/test-plotly-subplot.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ test_that("nrows argument works", {
3030
})
3131

3232
test_that("group + [x/y]axis works", {
33-
iris$id <- as.integer(iris$Species)
34-
p <- plot_ly(iris, x = ~Petal.Length, y = ~Petal.Width, color = ~Species,
35-
xaxis = ~paste0("x", id), mode = "markers")
33+
penguins <- palmerpenguins::penguins %>% tidyr::drop_na() %>% arrange(species)
34+
p <- plot_ly(penguins, x = ~bill_length_mm, y = ~bill_depth_mm, color = ~species,
35+
xaxis = ~paste0("x", as.integer(species)), mode = "markers")
3636
s <- expect_traces(subplot(p, margin = 0.05), 3, "group")
3737
ax <- s$layout[grepl("^[x-y]axis", names(s$layout))]
3838
doms <- lapply(ax, "[[", "domain")
@@ -136,7 +136,10 @@ test_that("subplot accepts a list of plots", {
136136

137137
test_that("ggplotly understands ggmatrix", {
138138
skip_if_not_installed("GGally")
139-
L <- expect_doppelganger_built(GGally::ggpairs(iris), "plotly-subplot-ggmatrix")
139+
penguins <- palmerpenguins::penguins %>% tidyr::drop_na() %>%
140+
select(species, bill_length_mm, bill_depth_mm, flipper_length_mm, body_mass_g)
141+
L <- expect_doppelganger_built(GGally::ggpairs(penguins),
142+
"plotly-subplot-ggmatrix")
140143
})
141144

142145
test_that("annotation paper repositioning", {

0 commit comments

Comments
 (0)