Open acvill opened 3 years ago
And here is a minimal reprex using the example from the plotly gradient scale help page
library(plotly)
df <- data.frame(
x = runif(100),
y = runif(100),
z1 = rnorm(100),
z2 = abs(rnorm(100))
)
df_na <- data.frame(
value = seq(1, 20),
x = runif(20),
y = runif(20),
z1 = c(rep(NA, 10), rnorm(10))
)
p <-
ggplot(df, aes(x, y)) +
geom_point(shape=21,
aes(fill = z1)) +
scale_fill_gradient2()
plotly::ggplotly(p)
generates this warning:
Warning message:
In L$marker$color[idx] <- aes2plotly(data, params, "fill")[idx] :
number of items to replace is not a multiple of replacement length
and this plot
> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] pillar_1.6.4 compiler_4.1.2 tools_4.1.2 digest_0.6.29
[5] viridisLite_0.4.0 jsonlite_1.7.2 lifecycle_1.0.1 tibble_3.1.6
[9] gtable_0.3.0 pkgconfig_2.0.3 rlang_0.4.12 DBI_1.1.2
[13] cli_3.1.0 rstudioapi_0.13 crosstalk_1.2.0 yaml_2.2.1
[17] fastmap_1.1.0 dplyr_1.0.7 httr_1.4.2 generics_0.1.1
[21] vctrs_0.3.8 htmlwidgets_1.5.4 grid_4.1.2 tidyselect_1.1.1
[25] glue_1.6.0 data.table_1.14.2 R6_2.5.1 fansi_0.5.0
[29] plotly_4.10.0.9000 farver_2.1.0 ggplot2_3.3.5 purrr_0.3.4
[33] tidyr_1.1.4 magrittr_2.0.1 scales_1.1.1 ellipsis_0.3.2
[37] htmltools_0.5.2 assertthat_0.2.1 colorspace_2.0-2 labeling_0.4.2
[41] utf8_1.2.2 lazyeval_0.2.2 munsell_0.5.0 crayon_1.4.2
Thank you for writing and maintaining plotly!
When making a scatterplot, I like to specify
pch = 21
to print an outline around points. This helps distinguish points when they are close together. When I use this plotting scheme, ggplot2 gives the expected output, but plotly ignores the aesthetics supplied byscale_fill_gradient2()
and gives the errornumber of items to replace is not a multiple of replacement length
. I believe this issue is similar to https://github.com/plotly/plotly.R/issues/1149.If I switch my mapping aesthetic to
color
withpch = 19
and specify a gradient withscale_color_gradient2()
, then ggplot2 and plotly give the same output without error. However, the desired outlines are lost.Here is my scheme for downloading the dataset, in case you want to troubleshoot with the same data: