ggplotly with "tooltip = text" is not working in a bar graph with + and - data
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- R
- Sterne
- 2.7k
- Forks
- 641
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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")
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Es werden keine Quelldateien oder Tests genannt. Beginne damit, das bereitgestellte R-Beispiel mit plotly::ggplotly() auszuführen, und vergleiche das Tooltip-Verhalten mit und ohne den kleinen y-limit-Offset. Als abgeschlossen gilt die Aufgabe, wenn tooltip = "text" für das Balkendiagramm mit sowohl positiven als auch negativen Daten funktioniert, ohne diesen Workaround zu erfordern.
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
- 42/100