plotly / plotly/plotly.R

plotly ignores scale_fill_gradient2

Offen
#2,073 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
R
Sterne
2.7k
Forks
641
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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()

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Führen Sie das bereitgestellte R-Beispiel aus und vergleichen Sie die ggplot2- und ggplotly-Ausgaben für pch = 21 mit scale_fill_gradient2(). Beginnen Sie beim ggplotly-Konvertierungspfad und verfolgen Sie, wie fill und Punktumrisse behandelt werden; als abgeschlossen gilt die Aufgabe, wenn das Beispiel keinen Fehler mehr verursacht, den Farbverlauf beibehält und die Umrisse erhält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
r
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.