plotly / plotly/plotly.R

Support "ggnewscale" through geom_NewGeomLine etc

オープン
#1,917 コメント 4 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提供された ggplotly の例を再現し、geom_NewGeomLine に対する geom2trace.default からの警告を追跡します。次に、ggplotly がこれらの生成された geoms をどのように処理するかを確認し、その後 ggnewscale の例に必要なサポートを特定して、報告された警告なしでレンダリングされることを検証します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
r
領域
data-visualization
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。