How do you get rid of the geom_text labels in ggplotly?

I want to keep the labels from geom_col when you hover over the columns, but remove the labels from geom_text (shown below).

How can I do this?


data <- iris %>% 
  pivot_longer(-Species, names_to = "indicator", values_to = "value") %>% 
  rename(species = Species) %>% 
  group_by(species, indicator) %>% 
  summarise(value = sum(value))

graph <- ggplot(data, aes(indicator, value, fill = species)) +
  geom_col(aes(text = paste0("Species:", species,
                             "</br></br>Indicator:", indicator,
                             "</br>Value:", value))) +
  geom_text(aes(label = value),
            position = position_stack(vjust = 0.5))

ggplotly(graph, tooltip = "text")

Worked it out. I think traces 1 to 3 are the from geom_col while 4 to 6 are from geom_text for this particular graph.

ggplotly(graph, tooltip = "text") %>%
  style(hoverinfo = "none", traces = c(4:6))
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.