plotly / plotly/plotly.R

ggplotly with "tooltip = text" is not working in a bar graph with + and - data

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

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

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

説明

ggplotly with "tooltip = text" does not work in a bar graph, where there is positive and negative data.

It does work if a very small number is added x_limits[1] inside geom_col.

It also works if "tooltip = text" is removed

This does not work:

library(tidyverse)

plot_data <- ggplot2::diamonds %>%
  mutate(cut = stringr::str_to_sentence(cut)) %>%
  group_by(cut) %>%
  summarise(average_price = mean(price)) %>%
  mutate(average_price = round(average_price / 1000, 1)) %>% 
  mutate(average_price = average_price - 4) %>% 
  ungroup() %>% 
  add_row(cut = "OK", average_price = NA) %>% 
  mutate(tip_text = "Hello!")

na_data <- plot_data %>% 
  filter(is.na(average_price)) 

breaks <- pretty(plot_data$average_price)

limits <- c(min(breaks), max(breaks))

plot_data <- plot_data %>% 
  mutate(id = row_number())

plot <- ggplot(data = plot_data) +
  geom_col(aes(y = average_price, x = cut, text = tip_text))  +
  coord_flip() +
  scale_y_continuous(breaks = breaks, limits = limits, expand = c(0, 0)) +
  geom_col(aes(y = limits[2], x = cut, text = tip_text), data = na_data) +
  geom_col(aes(y = limits[1], x = cut, text = tip_text), data = na_data)

plot  

plotly::ggplotly(plot, tooltip = "text") 

This does works:

library(tidyverse)

plot_data <- ggplot2::diamonds %>%
  mutate(cut = stringr::str_to_sentence(cut)) %>%
  group_by(cut) %>%
  summarise(average_price = mean(price)) %>%
  mutate(average_price = round(average_price / 1000, 1)) %>% 
  mutate(average_price = average_price - 4) %>% 
  ungroup() %>% 
  add_row(cut = "OK", average_price = NA) %>% 
  mutate(tip_text = "Hello!")

na_data <- plot_data %>% 
  filter(is.na(average_price)) 

breaks <- pretty(plot_data$average_price)

limits <- c(min(breaks), max(breaks))

plot_data <- plot_data %>% 
  mutate(id = row_number())

plot <- ggplot(data = plot_data) +
  geom_col(aes(y = average_price, x = cut, text = tip_text))  +
  coord_flip() +
  scale_y_continuous(breaks = breaks, limits = limits, expand = c(0, 0)) +
  geom_col(aes(y = limits[2], x = cut, text = tip_text), data = na_data) +
  geom_col(aes(y = limits[1] + 0.000001, x = cut, text = tip_text), data = na_data)

plot  

plotly::ggplotly(plot, tooltip = "text") 

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

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

はじめの一歩

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

調査の方向性

ソースファイルやテストは指定されていません。まず、提供されている R の例を plotly::ggplotly() で実行し、小さな y-limit オフセットありの場合となしの場合で tooltip の動作を比較してください。正のデータと負のデータの両方を含む棒グラフで、回避策を必要とせずに tooltip = "text" が機能すれば完了です。

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

評価

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

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

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