ggplotly with "tooltip = text" is not working in a bar graph with + and - data
Personne n'a encore pris cette issue.
- Langage dominant
- R
- Étoiles
- 2.7k
- Forks
- 641
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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")
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Aucun fichier source ni test n’est nommé. Commencez par exécuter l’exemple R fourni avec plotly::ggplotly() et comparez le comportement de l’info-bulle avec et sans le petit décalage de la limite de y. La tâche est terminée lorsque tooltip = "text" fonctionne pour le graphique à barres contenant des données à la fois positives et négatives sans nécessiter ce workaround.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- r
- Domaine
- data-visualization
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 42/100