plotly / plotly/plotly.R

geom_line() with text mapping and without group mapping doesn't render

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

Dieses Issue hat noch niemand übernommen.

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

Beschreibung

I have a base-barchart plot with working tooltips.

I want to add a line-chart by clicking a radioButton on top of the barchart, also with hovering tooltips, which is not working as I expected.

  1. When adding a text argument to the additional line, the line is not showing up, but when I hover over the pot, the labels of the line show.
  2. When uncommenting the text argument (line 28), the line shows, but no hovering tooltips, as expected.
  3. When removing the tooltip = "text" from the ggplotly call (line 33), the line and the tooltips shows up, but the formatting is not like I want it to be.

1 - kopie

library(shiny)
library(ggplot2)
library(plotly)

dfN <- data.frame(
  time_stamp = seq.Date(as.Date("2018-04-01"), as.Date("2018-07-30"), 1),
  val = runif(121, 100,1000),
  col = "green", stringsAsFactors = F
)

ui <- fluidPage(
  br(),br(),
  checkboxInput("zus1", value = FALSE, label = HTML("add Line")),
  plotlyOutput("plt")
)

server <- function(input, output, session) {
  output$plt <- renderPlotly({
    key <- highlight_key(dfN)
    p <- ggplot() +
      geom_col(data = key, aes(x = plotly:::to_milliseconds(time_stamp), y = val, fill=I(col),
                               text=paste("Datum: ", time_stamp, "<br>")))
    
    
    if (input$zus1 == TRUE) {
      p <- p + geom_line(data = dfN, aes(x = plotly:::to_milliseconds(dfN$time_stamp), y = val
                                         ## This text is not showing up, but hovering shows the labels
                                         # , text=paste("Value: ", val)
                                         ), color="red")
    }
    
    ## Removing tooltip = "text" shows the additional line and hover-labels but with horrible formatting.
    ggplotly(p, source = "Src") %>% 
      highlight(selectize=F, on="plotly_click", off = "plotly_doubleclick", color = "blue") %>% 
      layout(xaxis = list(tickval = NULL, ticktext = NULL, type = "date"))
  })
}

shinyApp(ui, server)

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

Beginnen Sie mit dem bereitgestellten Shiny-Beispiel und konzentrieren Sie sich auf die geom_line-Textzuordnung sowie den Aufruf ggplotly(p) mit tooltip="text". Stellen Sie den Fall nach, in dem die Linie ausgeblendet wird, ihre Beschriftungen jedoch angezeigt werden, und ermitteln Sie anschließend, durch welches Verhalten die Linie und korrekt formatierte Hover-Tooltips gemeinsam gerendert werden.

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.