Skip to content

Commit 5e5db59

Browse files
author
Julian Stanley
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")

0 commit comments

Comments
 (0)