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!