Support "ggnewscale" through geom_NewGeomLine etc
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
There are many use cases where a user wants to split a colour (or any other attribute) scale into multiple components. For example, if two separate types of data are being presented and it doesn't make sense to compare colours between these datasets.
In the example below, I am visualising a time series with time/y coordinates using geom_line, and also known timepoints that have only time coordinates using geom_vline. Note that this renders correctly using ggplot, but results in a blank plot and many errors with ggplotly:
require('dplyr')
#> Loading required package: dplyr
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
require('tidyr')
#> Loading required package: tidyr
require('tibble')
#> Loading required package: tibble
require('ggplot2')
#> Loading required package: ggplot2
require('ggnewscale')
#> Loading required package: ggnewscale
require('plotly')
#> Loading required package: plotly
#>
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#>
#> last_plot
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following object is masked from 'package:graphics':
#>
#> layout
series = rnorm(50*5) %>%
matrix(ncol=5) %>%
as_tibble() %>%
rownames_to_column() %>%
pivot_longer(cols=!rowname)
#> Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if `.name_repair` is omitted as of tibble 2.0.0.
#> Using compatibility `.name_repair`.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_warnings()` to see where this warning was generated.
changepoints = cbind(
x=sample(x=1:50, size=8, replace=T),
name=sample(x=c('a', 'b'), size=8, replace=T)
) %>%
as_tibble()
plt = ggplot() +
geom_line(data=series, aes(x=rowname, y=value, color=name, group=name)) +
new_scale_color() +
geom_vline(data=changepoints, aes(xintercept=x, color=name), size=1.5)
print(plt)

print(ggplotly(plt))
#> Warning in geom2trace.default(dots[[1L]][[5L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_NewGeomLine() has yet to be implemented in plotly.
#> If you'd like to see this geom implemented,
#> Please open an issue with your example code at
#> https://github.com/ropensci/plotly/issues
#> Warning in geom2trace.default(dots[[1L]][[5L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_NewGeomLine() has yet to be implemented in plotly.
#> If you'd like to see this geom implemented,
#> Please open an issue with your example code at
#> https://github.com/ropensci/plotly/issues
#> Warning in geom2trace.default(dots[[1L]][[5L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_NewGeomLine() has yet to be implemented in plotly.
#> If you'd like to see this geom implemented,
#> Please open an issue with your example code at
#> https://github.com/ropensci/plotly/issues
#> Warning in geom2trace.default(dots[[1L]][[5L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_NewGeomLine() has yet to be implemented in plotly.
#> If you'd like to see this geom implemented,
#> Please open an issue with your example code at
#> https://github.com/ropensci/plotly/issues
#> Warning in geom2trace.default(dots[[1L]][[5L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_NewGeomLine() has yet to be implemented in plotly.
#> If you'd like to see this geom implemented,
#> Please open an issue with your example code at
#> https://github.com/ropensci/plotly/issues
Created on 2021-02-12 by the reprex package (v1.0.0)
Ideally the entire package ggnewscale would be supported in ggplotly. Internally it seems to use functions such as geom_NewGeomLine, and these are the functions that plotly would need to implement to get this to work.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先复现提供的 ggplotly 示例,并跟踪 geom2trace.default 针对 geom_NewGeomLine 发出的警告。检查 ggplotly 如何处理这些生成的 geoms,然后确定对 ggnewscale 示例所需的支持,并验证其在没有报告中的警告的情况下能够渲染。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- r
- 领域
- data-visualization
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100