plotly / plotly/plotly.R

style(hoveron="fills") doesn't work with ggplotly() when there are multiple polygons with the same fill color

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

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

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

説明

The following code based on the standard North Carolina shape-file fills counties by the values of BIR74, except that one county has been given an NA value for the variable.

library(ggplot2)
library(plotly)
library(sf)

nc_1 <-
  st_read(system.file("shape/nc.shp", package = "sf"), 
              quiet = TRUE) %>% 
  mutate(BIR74 = ifelse(NAME == "Ashe", NA, BIR74)) %>% 
  mutate(tooltip_text = ifelse(is.na(BIR74), 
                               paste0(NAME, " not reporting"), 
                               paste0(NAME, " reports ", BIR74)))
p_1 <-
  nc_1 %>% 
  ggplot() +
  geom_sf(aes(fill = BIR74, text = tooltip_text))

ggplotly(p_1, tooltip = "text") %>% 
  style(hoveron = "fills")

The custom tooltip indicates the missing value (hover over Ashe County) as expected.

The following code sets BIR74 to NA for two counties:

nc_2 <-
  st_read(system.file("shape/nc.shp", package = "sf"), 
          quiet = TRUE) %>% 
  mutate(BIR74 = ifelse(NAME %in% c("Ashe", "Alleghany"), NA, BIR74)) %>% 
  mutate(tooltip_text = ifelse(is.na(BIR74), 
                               paste0(NAME, " not reporting"), 
                               paste0(NAME, " reports ", BIR74)))
p_2 <-
  nc_2 %>% 
  ggplot() +
  geom_sf(aes(fill = BIR74, text = tooltip_text))

ggplotly(p_2, tooltip = "text") %>% 
  style(hoveron = "fills")

Hover over either Ashe or Alleghany and you get identical very long tooltips.

The output of plotly_json(p_2) indicates that Ashe and Alleghany have somehow been combined. See, e.g.:

json_2 <- plotly_json(p_2)
json_2$x$data %>%
  as.character() %>% 
  RJSONIO::fromJSON() %>% 
  .$data %>% 
  .[[100]] %>% 
  .[1:3]

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

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

はじめの一歩

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

調査の方向性

2つの North Carolina の例を ggplotly()、tooltip = "text"、style(hoveron = "fills") で実行し、次に示されているとおり plotly_json(p_2) を調べます。one-NA のケースと two-NA のケースでポリゴンデータがどのように表現されるかを比較します。完了条件は、1つに結合された長い tooltip ではなく、Ashe と Alleghany がそれぞれ独自の tooltip を表示することです。

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

評価

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

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

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