diff --git a/DESCRIPTION b/DESCRIPTION index f32a09d427..c6e7188d40 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -74,7 +74,8 @@ Suggests: processx, plotlyGeoAssets, forcats, - thematic + thematic, + palmerpenguins LazyData: true RoxygenNote: 7.1.1 Encoding: UTF-8 diff --git a/R/ggplotly.R b/R/ggplotly.R index 5abf436f69..d6349da56a 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -36,8 +36,9 @@ #' @seealso [plot_ly()] #' @examples \dontrun{ #' # simple example -#' ggiris <- qplot(Petal.Width, Sepal.Length, data = iris, color = Species) -#' ggplotly(ggiris) +#' ggpenguins <- qplot(bill_length_mm , body_mass_g, +#' data = palmerpenguins::penguins, color = species) +#' ggplotly(ggpenguins) #' #' data(canada.cities, package = "maps") #' viz <- ggplot(canada.cities, aes(long, lat)) + @@ -58,7 +59,7 @@ #' demo("crosstalk-highlight-ggplotly", package = "plotly") #' #' # client-side linked brushing in a scatterplot matrix -#' highlight_key(iris) %>% +#' highlight_key(palmerpenguins::penguins) %>% #' GGally::ggpairs(aes(colour = Species), columns = 1:4) %>% #' ggplotly(tooltip = c("x", "y", "colour")) %>% #' highlight("plotly_selected") diff --git a/R/plotly.R b/R/plotly.R index 995816b588..e75035637f 100644 --- a/R/plotly.R +++ b/R/plotly.R @@ -118,12 +118,12 @@ #' # You might notice plot_ly() has named arguments that aren't in this figure #' # reference. These arguments make it easier to map abstract data values to #' # visual attributes. -#' p <- plot_ly(iris, x = ~Sepal.Width, y = ~Sepal.Length) -#' add_markers(p, color = ~Petal.Length, size = ~Petal.Length) -#' add_markers(p, color = ~Species) -#' add_markers(p, color = ~Species, colors = "Set1") -#' add_markers(p, symbol = ~Species) -#' add_paths(p, linetype = ~Species) +#' p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~body_mass_g) +#' add_markers(p, color = ~bill_depth_mm, size = ~bill_depth_mm) +#' add_markers(p, color = ~species) +#' add_markers(p, color = ~species, colors = "Set1") +#' add_markers(p, symbol = ~species) +#' add_paths(p, linetype = ~species) #' #' } #' diff --git a/man/ggplotly.Rd b/man/ggplotly.Rd index acd07647e6..d04030402d 100644 --- a/man/ggplotly.Rd +++ b/man/ggplotly.Rd @@ -60,8 +60,9 @@ shiny app, see \code{plotly_example("shiny", "ggplotly_sizing")}. \examples{ \dontrun{ # simple example -ggiris <- qplot(Petal.Width, Sepal.Length, data = iris, color = Species) -ggplotly(ggiris) +ggpenguins <- qplot(bill_length_mm , body_mass_g, +data = palmerpenguins::penguins, color = species) +ggplotly(ggpenguins) data(canada.cities, package = "maps") viz <- ggplot(canada.cities, aes(long, lat)) + @@ -82,7 +83,7 @@ qplot(data = d, x = mpg, y = wt) \%>\% demo("crosstalk-highlight-ggplotly", package = "plotly") # client-side linked brushing in a scatterplot matrix -highlight_key(iris) \%>\% +highlight_key(palmerpenguins::penguins) \%>\% GGally::ggpairs(aes(colour = Species), columns = 1:4) \%>\% ggplotly(tooltip = c("x", "y", "colour")) \%>\% highlight("plotly_selected") diff --git a/man/plot_ly.Rd b/man/plot_ly.Rd index c9b21fca81..f16bca6675 100644 --- a/man/plot_ly.Rd +++ b/man/plot_ly.Rd @@ -161,12 +161,12 @@ plot_ly(economics, x = ~date, color = I("black")) \%>\% # You might notice plot_ly() has named arguments that aren't in this figure # reference. These arguments make it easier to map abstract data values to # visual attributes. -p <- plot_ly(iris, x = ~Sepal.Width, y = ~Sepal.Length) -add_markers(p, color = ~Petal.Length, size = ~Petal.Length) -add_markers(p, color = ~Species) -add_markers(p, color = ~Species, colors = "Set1") -add_markers(p, symbol = ~Species) -add_paths(p, linetype = ~Species) +p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~body_mass_g) +add_markers(p, color = ~bill_depth_mm, size = ~bill_depth_mm) +add_markers(p, color = ~species) +add_markers(p, color = ~species, colors = "Set1") +add_markers(p, symbol = ~species) +add_paths(p, linetype = ~species) } diff --git a/tests/testthat/test-api.R b/tests/testthat/test-api.R index 1877ccd21f..d2d2231d10 100644 --- a/tests/testthat/test-api.R +++ b/tests/testthat/test-api.R @@ -93,7 +93,7 @@ test_that("Can overwrite a grid", { id <- new_id() m <- api_create(mtcars, id) - m2 <- api_create(iris, id) + m2 <- api_create(palmerpenguins::penguins, id) expect_true(identical(m$embed_url, m2$embed_url)) expect_false(identical(m$cols, m2$cols)) }) diff --git a/tests/testthat/test-ggplot-labels.R b/tests/testthat/test-ggplot-labels.R index 349e71acb3..d56588664d 100644 --- a/tests/testthat/test-ggplot-labels.R +++ b/tests/testthat/test-ggplot-labels.R @@ -1,41 +1,41 @@ context("labels") test_that("ggtitle is translated correctly", { - ggiris <- ggplot(iris) + - geom_point(aes(Petal.Width, Sepal.Width)) + + ggpenguin <- ggplot(palmerpenguins::penguins) + + geom_point(aes(bill_length_mm, bill_depth_mm)) + ggtitle("My amazing plot!") - info <- expect_doppelganger_built(ggiris, "labels-ggtitle") + info <- expect_doppelganger_built(ggpenguin, "labels-ggtitle") expect_identical(info$layout$title$text, "My amazing plot!") }) test_that("ylab is translated correctly", { - ggiris <- ggplot(iris) + - geom_point(aes(Petal.Width, Sepal.Width)) + - ylab("sepal width") - info <- expect_doppelganger_built(ggiris, "labels-ylab") + ggpenguin <- ggplot(palmerpenguins::penguins) + + geom_point(aes(bill_length_mm, bill_depth_mm)) + + ylab("bill depth") + info <- expect_doppelganger_built(ggpenguin, "labels-ylab") labs <- c(info$layout$xaxis$title$text, info$layout$yaxis$title$text) - expect_identical(labs, c("Petal.Width", "sepal width")) + expect_identical(labs, c("bill_length_mm", "bill depth")) }) test_that("scale_x_continuous(name) is translated correctly", { - ggiris <- ggplot(iris) + - geom_point(aes(Petal.Width, Sepal.Width)) + - scale_x_continuous("petal width") - info <- expect_doppelganger_built(ggiris, "labels-scale_x_continuous_name") + ggpenguin <- ggplot(palmerpenguins::penguins) + + geom_point(aes(bill_length_mm, bill_depth_mm)) + + scale_x_continuous("bill length") + info <- expect_doppelganger_built(ggpenguin, "labels-scale_x_continuous_name") labs <- c(info$layout$xaxis$title$text, info$layout$yaxis$title$text) - expect_identical(labs, c("petal width", "Sepal.Width")) + expect_identical(labs, c("bill length", "bill_depth_mm")) }) test_that("angled ticks are translated correctly", { - ggiris <- ggplot(iris) + - geom_point(aes(Petal.Width, Sepal.Width)) + + ggpenguin <- ggplot(palmerpenguins::penguins) + + geom_point(aes(bill_length_mm, bill_depth_mm)) + theme(axis.text.x = element_text(angle = 45)) - info <- expect_doppelganger_built(ggiris, "labels-angles") + info <- expect_doppelganger_built(ggpenguin, "labels-angles") expect_identical(info$layout$xaxis$tickangle, -45) }) test_that("xaxis/yaxis automargin defaults to TRUE", { - p <- ggplot(iris, aes(Species)) + geom_bar() + coord_flip() + p <- ggplot(palmerpenguins::penguins, aes(species)) + geom_bar() + coord_flip() l <- plotly_build(p)$x expect_true(l$layout$xaxis$automargin) expect_true(l$layout$yaxis$automargin) @@ -49,7 +49,8 @@ test_that("factor labels work", { }) test_that("empty labels work", { - p <- ggplot(iris, aes(Petal.Length, Sepal.Width, color = Species)) + + p <- ggplot(palmerpenguins::penguins, + aes(bill_length_mm, bill_depth_mm, color = species)) + geom_point() + labs(x = element_blank(), y = element_blank()) b <- expect_doppelganger_built(p, "labs-element-blank") diff --git a/tests/testthat/test-ggplot-legend.R b/tests/testthat/test-ggplot-legend.R index 5158f9e9ba..64bb0f4bfb 100644 --- a/tests/testthat/test-ggplot-legend.R +++ b/tests/testthat/test-ggplot-legend.R @@ -72,8 +72,9 @@ test_that("very long legend items", { info <- expect_traces(p_long_items, 3, "very-long-legend-items") }) -iris$All <- "All species" -p <- qplot(data = iris, x = Sepal.Length, y = Sepal.Width, color = All) +penguins <- palmerpenguins::penguins +penguins$All <- "All species" +p <- qplot(data = penguins, x = bill_length_mm, y = bill_depth_mm, color = All) test_that("legend is created with discrete mapping regardless of unique values", { info <- expect_traces(p, 1, "one-entry") diff --git a/tests/testthat/test-ggplot-size.R b/tests/testthat/test-ggplot-size.R index 4aad47f1c3..14d6ed06d2 100644 --- a/tests/testthat/test-ggplot-size.R +++ b/tests/testthat/test-ggplot-size.R @@ -1,9 +1,9 @@ context("size") test_that("size is a vector if it is specified", { - iplot <- ggplot(iris) + - geom_point(aes(Petal.Width, Sepal.Width, size=Petal.Length)) - L <- expect_doppelganger_built(iplot, "size-is-a-vector") + pplot <- ggplot(palmerpenguins::penguins) + + geom_point(aes(bill_length_mm, bill_depth_mm, size=flipper_length_mm)) + L <- expect_doppelganger_built(pplot, "size-is-a-vector") m <- L$data[[1]]$marker expect_that(m, is_a("list")) expect_true(length(m$size) > 1) diff --git a/tests/testthat/test-ggplot-theme.R b/tests/testthat/test-ggplot-theme.R index 63e6fc7665..851a013a8a 100644 --- a/tests/testthat/test-ggplot-theme.R +++ b/tests/testthat/test-ggplot-theme.R @@ -1,24 +1,24 @@ context("ggplot themes") -iris.base <- ggplot(iris) + - geom_point(aes(Petal.Width, Sepal.Width)) + +penguin.base <- ggplot(palmerpenguins::penguins) + + geom_point(aes(bill_length_mm, bill_length_mm)) + theme_grey() test_that("background translated correctly",{ - ggiris <- iris.base + + ggpenguin <- penguin.base + theme(panel.background = element_rect(fill = "blue"), plot.background = element_rect(fill = "green")) - info <- expect_doppelganger_built(ggiris, "theme-background") + info <- expect_doppelganger_built(ggpenguin, "theme-background") L <- info$layout expect_true(L$plot_bgcolor == toRGB("blue")) expect_true(L$paper_bgcolor == toRGB("green")) }) test_that("grid/ticks translated correctly",{ - ggiris <- iris.base + + ggpenguin <- penguin.base + theme(axis.ticks = element_line(colour = "red"), panel.grid.major = element_line(colour = "violet")) - info <- expect_doppelganger_built(ggiris, "theme-ticks-and-grids") + info <- expect_doppelganger_built(ggpenguin, "theme-ticks-and-grids") for (xy in c("x", "y")) { ax.list <- info$layout[[paste0(xy, "axis")]] expect_true(ax.list$tickcolor == toRGB("red")) @@ -27,8 +27,8 @@ test_that("grid/ticks translated correctly",{ }) test_that("show ticks as 'outside' by default", { - ggiris <- iris.base - info <- expect_doppelganger_built(ggiris, "theme-ticks-default") + ggpenguin <- penguin.base + info <- expect_doppelganger_built(ggpenguin, "theme-ticks-default") for (xy in c("x", "y")) { ax.list <- info$layout[[paste0(xy, "axis")]] expect_identical(ax.list$ticks, "outside") @@ -36,8 +36,8 @@ test_that("show ticks as 'outside' by default", { }) test_that("do not show zeroline by default", { - ggiris <- iris.base - info <- expect_doppelganger_built(ggiris, "theme-zeroline-default") + ggpenguin <- penguin.base + info <- expect_doppelganger_built(ggpenguin, "theme-zeroline-default") for (xy in c("x", "y")) { ax.list <- info$layout[[paste0(xy, "axis")]] expect_identical(ax.list$zeroline, FALSE) @@ -63,12 +63,12 @@ test_that("marker default shape is a circle", { }) test_that("plot panel border is translated correctly", { - ggiris <- iris.base + theme_grey() # has no panel.border - info <- expect_doppelganger_built(ggiris, "theme-panel-border-1") + ggpenguin <- penguin.base + theme_grey() # has no panel.border + info <- expect_doppelganger_built(ggpenguin, "theme-panel-border-1") - red <- ggplot(iris) + + red <- ggplot(palmerpenguins::penguins) + theme_grey() + - geom_point(aes(Petal.Width, Sepal.Width)) + + geom_point(aes(bill_length_mm, bill_depth_mm)) + theme(panel.border = element_rect(colour = "red", fill = NA)) info <- expect_doppelganger_built(red, "theme-panel-border-2") diff --git a/tests/testthat/test-plotly-color.R b/tests/testthat/test-plotly-color.R index d930a9e799..858b1b8d25 100644 --- a/tests/testthat/test-plotly-color.R +++ b/tests/testthat/test-plotly-color.R @@ -8,11 +8,11 @@ expect_traces <- function(p, n.traces, name){ } test_that("plot_ly() handles a simple scatterplot", { - p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Petal.Width) + p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_length_mm, color = ~bill_depth_mm) }) test_that("Mapping a factor variable to color works", { - p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Species) + p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_length_mm, color = ~species) l <- expect_traces(p, 3, "scatterplot-color-factor") markers <- lapply(l$data, "[[", "marker") cols <- unlist(lapply(markers, "[[", "color")) @@ -24,7 +24,7 @@ test_that("Custom RColorBrewer pallette works for factor variable", { # convert hex to rgba spec for comparison's sake colsToCompare <- toRGB(cols) # specifying a pallette set should "span the gamut" - p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Species, + p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_length_mm, color = ~species, colors = "Set1") l <- expect_traces(p, 3, "scatterplot-color-factor-custom") markers <- lapply(l$data, "[[", "marker") @@ -32,7 +32,7 @@ test_that("Custom RColorBrewer pallette works for factor variable", { idx <- if (packageVersion("scales") > '1.0.0') c(1, 2, 3) else c(1, 5, 9) expect_identical(sort(colsToCompare[idx]), sort(colz)) # providing vector of RGB codes should also work - p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Species, + p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_length_mm, color = ~species, colors = cols[1:3]) l <- expect_traces(p, 3, "scatterplot-color-factor-custom2") markers <- lapply(l$data, "[[", "marker") @@ -51,16 +51,16 @@ test_that("Passing hex codes to colors argument works", { }) test_that("Mapping a numeric variable to color works", { - p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Petal.Width) + p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_length_mm, color = ~bill_depth_mm) # one trace is for the colorbar l <- expect_traces(p, 2, "scatterplot-color-numeric") idx <- vapply(l$data, is.colorbar, logical(1)) markerScale <- l$data[[which(idx)]]$marker markerDat <- l$data[[which(!idx)]]$marker - expect_true(all(markerDat$color == iris$Petal.Width)) - expect_true(markerScale$colorbar$title == "Petal.Width") - expect_true(min(iris$Petal.Width) == markerScale$cmin) - expect_true(max(iris$Petal.Width) == markerScale$cmax) + expect_true(all(markerDat$color == na.omit(palmerpenguins::penguins$bill_depth_mm))) + expect_true(markerScale$colorbar$title == "bill_depth_mm") + expect_true(min(na.omit(palmerpenguins::penguins$bill_depth_mm)) == markerScale$cmin) + expect_true(max(na.omit(palmerpenguins::penguins$bill_depth_mm)) == markerScale$cmax) expect_true(all(0 <= markerScale$colorscale[,1] & markerScale$colorscale[,1] <= 1)) }) @@ -76,20 +76,20 @@ test_that("color/stroke mapping with box translates correctly", { }) test_that("Custom RColorBrewer pallette works for numeric variable", { - p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, - color = ~Petal.Width, colors = "Greens") + p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_length_mm, + color = ~bill_depth_mm, colors = "Greens") # one trace is for the colorbar l <- expect_traces(p, 2, "scatterplot-color-numeric-custom") }) test_that("axis titles get attached to scene object for 3D plots", { - p <- plot_ly(iris, x = ~Petal.Length, y = ~Petal.Width, z = ~Sepal.Width) + p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_depth_mm, z = ~flipper_length_mm) l <- expect_traces(p, 1, "scatterplot-scatter3d-axes") expect_identical(l$data[[1]]$type, "scatter3d") scene <- l$layout$scene - expect_true(scene$xaxis$title == "Petal.Length") - expect_true(scene$yaxis$title == "Petal.Width") - expect_true(scene$zaxis$title == "Sepal.Width") + expect_true(scene$xaxis$title == "bill_length_mm") + expect_true(scene$yaxis$title == "bill_depth_mm") + expect_true(scene$zaxis$title == "flipper_length_mm") }) test_that("Can specify a scale manually", { diff --git a/tests/testthat/test-plotly-subplot.R b/tests/testthat/test-plotly-subplot.R index 3f52805b3c..bb1e7c5baa 100644 --- a/tests/testthat/test-plotly-subplot.R +++ b/tests/testthat/test-plotly-subplot.R @@ -30,9 +30,9 @@ test_that("nrows argument works", { }) test_that("group + [x/y]axis works", { - iris$id <- as.integer(iris$Species) - p <- plot_ly(iris, x = ~Petal.Length, y = ~Petal.Width, color = ~Species, - xaxis = ~paste0("x", id), mode = "markers") + penguins <- palmerpenguins::penguins %>% tidyr::drop_na() %>% arrange(species) + p <- plot_ly(penguins, x = ~bill_length_mm, y = ~bill_depth_mm, color = ~species, + xaxis = ~paste0("x", as.integer(species)), mode = "markers") s <- expect_traces(subplot(p, margin = 0.05), 3, "group") ax <- s$layout[grepl("^[x-y]axis", names(s$layout))] doms <- lapply(ax, "[[", "domain") @@ -136,7 +136,10 @@ test_that("subplot accepts a list of plots", { test_that("ggplotly understands ggmatrix", { skip_if_not_installed("GGally") - L <- expect_doppelganger_built(GGally::ggpairs(iris), "plotly-subplot-ggmatrix") + penguins <- palmerpenguins::penguins %>% tidyr::drop_na() %>% + select(species, bill_length_mm, bill_depth_mm, flipper_length_mm, body_mass_g) + L <- expect_doppelganger_built(GGally::ggpairs(penguins), + "plotly-subplot-ggmatrix") }) test_that("annotation paper repositioning", { diff --git a/tests/testthat/test-plotly-symbol.R b/tests/testthat/test-plotly-symbol.R index d41fcedc31..b13b89eb5a 100644 --- a/tests/testthat/test-plotly-symbol.R +++ b/tests/testthat/test-plotly-symbol.R @@ -8,7 +8,8 @@ expect_traces <- function(p, n.traces, name){ } test_that("Mapping a variable to symbol works", { - p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, symbol = ~Species) + p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, + y = ~bill_depth_mm, symbol = ~species) l <- expect_traces(p, 3, "scatterplot-symbol") markers <- lapply(l$data, "[[", "marker") syms <- unlist(lapply(markers, "[[", "symbol")) @@ -16,8 +17,8 @@ test_that("Mapping a variable to symbol works", { }) test_that("Can set the symbol range.", { - p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, symbol = ~Species, - symbols = 1:3) + p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, + y = ~bill_depth_mm, symbol = ~species, symbols = 1:3) l <- expect_traces(p, 3, "scatterplot-symbol2") markers <- lapply(l$data, "[[", "marker") syms <- unlist(lapply(markers, "[[", "symbol")) @@ -26,7 +27,7 @@ test_that("Can set the symbol range.", { test_that("Setting a constant symbol works", { - p <- plot_ly(iris, x = 1:25, y = 1:25, symbol = I(0:24)) + p <- plot_ly(palmerpenguins::penguins, x = 1:25, y = 1:25, symbol = I(0:24)) l <- expect_traces(p, 1, "pch") markers <- lapply(l$data, "[[", "marker") syms <- unlist(lapply(markers, "[[", "symbol")) @@ -34,7 +35,7 @@ test_that("Setting a constant symbol works", { }) test_that("Warn about invalid symbol codes", { - p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, symbol = I("DNE")) + p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_depth_mm, symbol = I("DNE")) expect_warning(plotly_build(p), "DNE") }) diff --git a/tests/testthat/test-plotly.R b/tests/testthat/test-plotly.R index 9bf610297d..98d6bf7207 100644 --- a/tests/testthat/test-plotly.R +++ b/tests/testthat/test-plotly.R @@ -55,21 +55,22 @@ test_that("Variable mappings return same result regardless of where they appear" test_that("plot_ly() handles a simple scatterplot", { - p <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, mode = "markers") + p <- plot_ly(data = palmerpenguins::penguins, + x = ~bill_length_mm, y = ~bill_depth_mm, mode = "markers") l <- expect_traces(p, 1, "scatterplot") expect_equivalent(l$data[[1]]$mode, "markers") - expect_equivalent(l$data[[1]]$x, iris$Sepal.Length) - expect_equivalent(l$data[[1]]$y, iris$Petal.Length) - expect_true(l$layout$xaxis$title == "Sepal.Length") - expect_true(l$layout$yaxis$title == "Petal.Length") + expect_equivalent(l$data[[1]]$x, na.omit(palmerpenguins::penguins$bill_length_mm)) + expect_equivalent(l$data[[1]]$y, na.omit(palmerpenguins::penguins$bill_depth_mm)) + expect_true(l$layout$xaxis$title == "bill_length_mm") + expect_true(l$layout$yaxis$title == "bill_depth_mm") expect_true(l$layout$xaxis$automargin) expect_true(l$layout$yaxis$automargin) }) test_that("type inference + add_data + layering works as expected", { -p <- plot_ly(iris, x = ~Species) %>% +p <- plot_ly(palmerpenguins::penguins, x = ~species) %>% add_trace(opacity = 0.3) %>% - add_data(iris[sample(nrow(iris), 10), ]) %>% + add_data(palmerpenguins::penguins[sample(nrow(palmerpenguins::penguins), 10), ]) %>% add_trace() %>% layout(barmode = "overlay") l <- expect_traces(p, 2, "bar-inference") @@ -322,8 +323,9 @@ test_that("Line breaks are properly translated (R -> HTML)", { # create target labels suffix <- "\n\n(third line)\n(fourth line)" - target_labels <- iris$Species %>% + target_labels <- palmerpenguins::penguins$species %>% unique() %>% + sort() %>% paste0(suffix) %>% gsub(pattern = "\n", replacement = br(), @@ -331,19 +333,19 @@ test_that("Line breaks are properly translated (R -> HTML)", { fixed = TRUE) # test factor column - d <- iris - levels(d$Species) <- paste0(levels(d$Species), suffix) - p1 <- d %>% plot_ly(x = ~Sepal.Length, - y = ~Species) + d <- palmerpenguins::penguins + levels(d$species) <- paste0(levels(d$species), suffix) + p1 <- d %>% plot_ly(x = ~bill_length_mm, + y = ~species) expect_equivalent(plotly_build(p1)[["x"]][["layout"]][["yaxis"]][["categoryarray"]], target_labels) # test character column p2 <- d %>% - dplyr::mutate(Species = as.character(Species)) %>% - plot_ly(x = ~Sepal.Length, - y = ~Species) + dplyr::mutate(species = as.character(species)) %>% + plot_ly(x = ~bill_length_mm, + y = ~species) expect_equivalent(plotly_build(p2)[["x"]][["layout"]][["yaxis"]][["categoryarray"]], target_labels)