0

I have successfully edited tooltips on line graphs before using the text = paste() function. However, I am having trouble working out how to do it on a histogram where y = ..count..

I want to change 'count:' on the tooltip to 'Number of shark attacks:' and keep the other text the same. The code below allows me to add 'Number of shark attacks' but does not remove 'count':

plot <- ggplot(data = aus_states, aes(x = Area, y = ..count.., fill = Fatal,
                                    text = paste("Number of shark attacks:", ..count..),
                  )
             )+
  geom_bar(position = position_dodge(width = 0.5)) +
   xlab("Year") +
    ylab("Number of shark attacks") +
     scale_fill_manual(values = c("lightseagreen", "pink", "brown2")) +
      scale_y_continuous(breaks=seq(0,200,20)) +
        theme_light()

labs = c("Area \nunknown", "New South\n Wales", "Northern\nTerritory", "Queensland", "South\nAustralia", "Victoria", "Western\nAustralia")

ggplotly(plot + scale_x_discrete(labels=labs) +
  theme(text = element_text(family="Georgia"))) %>% 
   layout(legend = list(orientation = "h", x = 0.325, y = -0.2))

I hope that makes sense. Thanks to anyone who helps!

  • 1
    I would try the option `tooltip = "text"` in `ggplotly`. – Stéphane Laurent Apr 24 '21 at 17:10
  • It would be easier to help if you create a small reproducible example along with expected output. Read about [how to give a reproducible example](http://stackoverflow.com/questions/5963269). – Ronak Shah Apr 25 '21 at 02:23

0 Answers0