plotly / plotly/plotly.R

plotly ignores scale_fill_gradient2

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

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

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

説明

Thank you for writing and maintaining plotly!

When making a scatterplot, I like to specify pch = 21 to print an outline around points. This helps distinguish points when they are close together. When I use this plotting scheme, ggplot2 gives the expected output, but plotly ignores the aesthetics supplied by scale_fill_gradient2() and gives the error number of items to replace is not a multiple of replacement length. I believe this issue is similar to https://github.com/plotly/plotly.R/issues/1149.

# R v4.0.5
library(plotly) # v 4.9.4.1
library(ggplot2) # v 3.3.3

p <- ggplot(data = wdat, mapping = aes(x = Age, y = as.numeric(ABV))) +
  geom_jitter(mapping = aes(fill = Score), size = 2.5, pch = 21) +
  scale_fill_gradient2(low = "#0008ff",
                       midpoint = mean(wdat$Score),
                       mid = "purple",
                       high = "#ff0000") +
  scale_y_continuous(name = "% ABV",
                     limits = c(40, 70),
                     breaks = seq(from = 40, 70, 5)) +
  theme_classic()

p + ggtitle("ggplot2")

ggplotly(p + ggtitle("plotly"))

ggplot2
plotly

If I switch my mapping aesthetic to color with pch = 19 and specify a gradient with scale_color_gradient2(), then ggplot2 and plotly give the same output without error. However, the desired outlines are lost.

p <- ggplot(data = wdat, mapping = aes(x = Age, y = as.numeric(ABV))) +
  geom_jitter(mapping = aes(color = Score), size = 2.5, pch = 19) +
  scale_color_gradient2(low = "#0008ff",
                       midpoint = mean(wdat$Score),
                       mid = "purple",
                       high = "#ff0000") +
  scale_y_continuous(name = "% ABV",
                     limits = c(40, 70),
                     breaks = seq(from = 40, 70, 5)) +
  theme_classic()

p + ggtitle("ggplot2")

ggplotly(p + ggtitle("plotly"))

ggplot2b
plotlyb

Here is my scheme for downloading the dataset, in case you want to troubleshoot with the same data:

library(dplyr) # v 1.0.5
library(gsheet) # v 0.4.5

url <- "https://docs.google.com/spreadsheets/d/1geSFmGKWhoSzoSblQQK6fDzWSujY-MQ9w2b3VNbTxZk"

wdat <- gsheet::construct_download_url(url = url) %>%
  gsheet::gsheet2tbl(url = .) %>%
  mutate(ABV = gsub("%","",ABV) %>%
           as.numeric() %>%
           round(., 3) %>%
           format(., nsmall = 1)) %>%
  na.omit()

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

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

はじめの一歩

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

調査の方向性

提供された R の例を実行し、scale_fill_gradient2() を使用した pch = 21 について ggplot2 と ggplotly の出力を比較します。ggplotly の変換パスから始めて、fill と点の輪郭がどのように処理されるかを追跡します。完了の条件は、例でエラーが発生しなくなり、グラデーションが保持され、輪郭が維持されることです。

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

評価

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

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

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