plotly / plotly/plotly.R

`ggplotly` produces error when using `geom_area` or `geom_line(position = "stack")` across frames

未关闭
#2,091 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

描述

When using ggplotly to convert from a ggplot object, R produces an error when:

  • using geom_area() (default position = "stack") or geom_line(position = "stack")
  • splitting lines/areas by multiple groups (for stacking)
  • animating across frames

These both produce the error "Error in -data$group: invalid argument to unary operator". Reprex below.

library(ggplot2)
library(dplyr)
library(plotly)


# Working plot with `position = "identity"`
plt1 <- {
  tibble(
    a = rep(rep(1:5, each = 2), 2),
    b = sample(1:10, 20, replace = TRUE),
    group = rep(c("a", "b"), 10),
    frame = rep(1:2, each = 10)
  ) %>%
    ggplot(aes(a, b, colour = group, frame = frame)) +
    geom_line()
} %>%
  ggplotly

# Two plots not working, both `position = "stack"`
plt2 <- {
  tibble(
    a = rep(rep(1:5, each = 2), 2),
    b = sample(1:10, 20, replace = TRUE),
    group = rep(c("a", "b"), 10),
    frame = rep(1:2, each = 10)
  ) %>%
    ggplot(aes(a, b, colour = group, frame = frame)) +
    geom_line(position = "stack")
} %>%
  ggplotly
#> Error in -data$group: invalid argument to unary operator


plt3 <- {
  tibble(
    a = rep(rep(1:5, each = 2), 2),
    b = sample(1:10, 20, replace = TRUE),
    group = rep(c("a", "b"), 10),
    frame = rep(1:2, each = 10)
  ) %>%
    ggplot(aes(a, b, fill = group, frame = frame)) +
    geom_area()
} %>%
  ggplotly
#> Error in -data$group: invalid argument to unary operator

Created on 2021-12-21 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> - Session info  --------------------------------------------------------------
#>  hash: oncoming police car, eye in speech bubble, toilet
#> 
#>  setting  value
#>  version  R version 4.1.1 (2021-08-10)
#>  os       Windows 10 x64 (build 19041)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United Kingdom.1252
#>  ctype    English_United Kingdom.1252
#>  tz       Europe/London
#>  date     2021-12-21
#>  pandoc   2.14.0.3 @ C:/Program Files/RStudio/bin/pandoc/ (via rmarkdown)
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version date (UTC) lib source
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.1.0)
#>  backports     1.3.0   2021-10-27 [1] CRAN (R 4.1.1)
#>  cli           3.1.0   2021-10-27 [1] CRAN (R 4.1.1)
#>  colorspace    2.0-2   2021-06-24 [1] CRAN (R 4.1.1)
#>  crayon        1.4.2   2021-10-29 [1] CRAN (R 4.1.1)
#>  crosstalk     1.2.0   2021-11-04 [1] CRAN (R 4.1.1)
#>  data.table    1.14.2  2021-09-27 [1] CRAN (R 4.1.1)
#>  DBI           1.1.1   2021-01-15 [1] CRAN (R 4.1.0)
#>  digest        0.6.28  2021-09-23 [1] CRAN (R 4.1.1)
#>  dplyr       * 1.0.7   2021-06-18 [1] CRAN (R 4.1.1)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.1.0)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.1.0)
#>  fansi         0.5.0   2021-05-25 [1] CRAN (R 4.1.0)
#>  farver        2.1.0   2021-02-28 [1] CRAN (R 4.1.0)
#>  fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.1.0)
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.1.0)
#>  generics      0.1.1   2021-10-25 [1] CRAN (R 4.1.1)
#>  ggplot2     * 3.3.5   2021-06-25 [1] CRAN (R 4.1.1)
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.1.0)
#>  gtable        0.3.0   2019-03-25 [1] CRAN (R 4.1.0)
#>  highr         0.9     2021-04-16 [1] CRAN (R 4.1.0)
#>  htmltools     0.5.2   2021-08-25 [1] CRAN (R 4.1.1)
#>  htmlwidgets   1.5.4   2021-09-08 [1] CRAN (R 4.1.1)
#>  httr          1.4.2   2020-07-20 [1] CRAN (R 4.1.0)
#>  jsonlite      1.7.2   2020-12-09 [1] CRAN (R 4.1.0)
#>  knitr         1.36    2021-09-29 [1] CRAN (R 4.1.1)
#>  labeling      0.4.2   2020-10-20 [1] CRAN (R 4.1.0)
#>  lazyeval      0.2.2   2019-03-15 [1] CRAN (R 4.1.0)
#>  lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.1.1)
#>  magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.0.3)
#>  munsell       0.5.0   2018-06-12 [1] CRAN (R 4.1.0)
#>  pillar        1.6.4   2021-10-18 [1] CRAN (R 4.1.1)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.1.0)
#>  plotly      * 4.10.0  2021-10-09 [1] CRAN (R 4.1.1)
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.1.0)
#>  R.cache       0.15.0  2021-04-30 [1] CRAN (R 4.1.0)
#>  R.methodsS3   1.8.1   2020-08-26 [1] CRAN (R 4.1.0)
#>  R.oo          1.24.0  2020-08-26 [1] CRAN (R 4.1.0)
#>  R.utils       2.11.0  2021-09-26 [1] CRAN (R 4.1.1)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.1.1)
#>  reprex        2.0.1   2021-08-05 [1] CRAN (R 4.1.1)
#>  rlang         0.4.12  2021-10-18 [1] CRAN (R 4.1.1)
#>  rmarkdown     2.11    2021-09-14 [1] CRAN (R 4.1.1)
#>  rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.1.0)
#>  scales        1.1.1   2020-05-11 [1] CRAN (R 4.1.0)
#>  sessioninfo   1.2.1   2021-11-02 [1] CRAN (R 4.1.1)
#>  stringi       1.7.5   2021-10-04 [1] CRAN (R 4.1.1)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.1.0)
#>  styler        1.6.2   2021-09-23 [1] CRAN (R 4.1.1)
#>  tibble        3.1.5   2021-09-30 [1] CRAN (R 4.1.1)
#>  tidyr         1.1.4   2021-09-27 [1] CRAN (R 4.1.1)
#>  tidyselect    1.1.1   2021-04-30 [1] CRAN (R 4.1.0)
#>  utf8          1.2.2   2021-07-24 [1] CRAN (R 4.1.1)
#>  vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.1.0)
#>  viridisLite   0.4.0   2021-04-13 [1] CRAN (R 4.1.0)
#>  withr         2.4.3   2021-11-30 [1] CRAN (R 4.1.2)
#>  xfun          0.28    2021-11-04 [1] CRAN (R 4.1.1)
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.1.0)
#> 
#>  [1] C:/R Packages
#>  [2] C:/Program Files/R/R-4.1.1/library
#> 
#> ------------------------------------------------------------------------------

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用 ggplotly 运行提供的 reprex,比较可正常工作的 position = "identity" 情况与跨多个 frame 的 geom_line(position = "stack") 和 geom_area。跟踪面向分组动画数据的 ggplotly 转换路径,并添加回归覆盖,证明这两种 stacking 情况都不再产生所报告的错误。

由索引模型根据 Issue 内容生成。

评估

技术栈
r
领域
data-visualization
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。