Hovertemplate shows data twice when used with add_trace() in plotly

Viewed 101

I create the grouped bar chart below using plotly. The issue is that in my hovertemplate for trace I get a white box with LA_ZOO which seems to be unnecessary and I want to get rid of.

Animals <- c("giraffes", "orangutans", "monkeys")
SF_Zoo <- c(20, 14, 23)
LA_Zoo <- c(12, 18, 29)
data <- data.frame(Animals, SF_Zoo, LA_Zoo)
library(plotly)
fig <- plot_ly(data, x = ~Animals, y = ~SF_Zoo, type = 'bar', name = 'SF_ZOO',marker=list(color="#556361"),
               hovertemplate = paste('<b>Month</b>: %{x}',
                                     '<br><b>SF_ZOO</b>: %{y}<br>'
               ))
fig <- fig %>% add_trace(y = ~LA_Zoo, name = 'LA_ZOO',marker=list(color="#A72608"),
                         hovertemplate = paste('<b>Month</b>: %{x}',
                                               '<br><b>LA_ZOO</b>: %{y}<br>'
                         ))

fig <- fig %>% layout(yaxis = list(title = 'Count'), barmode = 'group')

fig
0 Answers
Related