plotly / plotly/plotly.R

bug with the font parameter for annotation

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

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

bug
主要言語
R
スター
2.7k
フォーク
641
PR マージ指標
30日以内にマージされた PR はありません

説明

I want to add an annotation to a plotly heatmap. There is a bug with the font parameter. I've followed the example given here.

library(plotly)

### heatmap data ### 
x <- 1:3; y <- 3:5
dd <- transform(expand.grid(x=x, y=y), z=x+y)

### plotly graphic ###
pp <- plot_ly(data=dd, x=~x, y=~y, z=~z, type="heatmap",
              hoverinfo = 'text',
              text = ~paste('<em>x</em>: ', dd$x, 
                            '</br> <em>y</em>: ', dd$y,
                            '</br> <em>z</em>: ', dd$z)) %>%
  layout(xaxis=list(title="<em>xaxis title</em>"))

### add annotation ###
pp <- pp %>% 
  add_annotations(  x = 1,
                    y = 4,
                    text = "<em>MY ANNOTATION</em>",
                    xref = "x",
                    yref = "y",
                    showarrow = TRUE,
                    arrowhead = 7,
                    ax = 10,
                    ay = 30,
                    font = list(color = 'red',
                                family = 'sans serif',
                                size = 24)
  )

That does not yield the expected result:

rplot_annotation

In fact, the problem lies in the fact that plotly_build generates three annotation layouts, one for each parameter of the font list:

> bpp <- plotly_build(pp)
> annotation <- bpp$x$layout$annotations
> length(annotation)
[1] 3
> sapply(annotation, function(x) x$font)
[1] "red"        "sans serif" "24"  

Thus, here is a way to get the expected result:

myannotation <- annotation[[1]]
myannotation$font <-  list(color = 'red',
                           family = 'sans serif',
                           size = 24)
bpp$x$layout$annotations <- myannotation
bpp

rplot_annotation_good

> packageVersion("plotly")
[1] ‘4.5.2’

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

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

はじめの一歩

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

調査の方向性

まず、提供されている R ヒートマップの例を実行し、plotly_build(pp) の出力、特に x$layout$annotations を調べます。add_annotations が font リストをどのように処理するかを追跡します。color、family、size が 3 つの annotation を生成するのではなく、1 つの annotation 上の 1 つの font オブジェクトとして保持されれば完了です。

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

評価

技術スタック
r
領域
data-visualization
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

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

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