Consider the following data:
> data_graph_1
# A tibble: 3 × 4
trust_pm3cat yes_no_share yes_share no_share
<fctr> <dbl> <dbl> <dbl>
1 tief -0.76581 0.11710 0.882904
2 mittel 0.12500 0.56250 0.437500
3 hoch 0.85593 0.92797 0.072034
When I create a plotly chart with the following code, the hover text doesn’t appear. I’ve uploaded the chart here.
data_graph_1 %>%
plot_ly(x = ~trust_pm3cat,
y = ~yes_no_share,
text = paste0("Anteil Ja-/Nein-Stimmen: ", round(data_graph_1$yes_no_share, digits = 2),
"<br><br>Ja-Stimmenanteil: ", round(data_graph_1$yes_share * 100, digits = 2), " %",
"<br>Nein-Stimmenanteil: ", round(data_graph_1$no_share * 100, digits = 2), " %"),
hoverinfo = "x+text",
color = ~trust_pm3cat,
colors = c("#EDD02E", "#CCCCCC", "#44187C"),
opacity = 0.8) %>%
add_bars() %>%
layout(title = "<b>Ja-/Nein-Stimmenanteil</b><br>je nach Vertrauen in Ministerpräsident Renzi",
xaxis = list(title = "Vertrauen in Ministerpräsident Matteo Renzi",
fixedrange = TRUE,
zeroline = FALSE),
yaxis = list(title = "Anteil Ja-/Nein-Stimmen<br>von -1 (100 % Nein-Stimmen) bis 1 (100 % Ja-Stimmen)<br> ",
fixedrange = TRUE),
font = list(family = "Work Sans"),
legend = list(traceorder = "normal",
orientation = "v"),
margin = list(l = 80,
r = 0,
t = 60,
b = 60,
pad = 0,
autoexpand = TRUE)) %>%
hide_legend() %>%
config(displaylogo = FALSE,
showLink = FALSE,
displayModeBar = FALSE)
But if I instead define the colors in marker = list(color = ...)
everything works fine. I’ve also uploaded this chart here.
data_graph_1 %>%
plot_ly(x = ~trust_pm3cat,
y = ~yes_no_share,
text = paste0("Anteil Ja-/Nein-Stimmen: ", round(data_graph_1$yes_no_share, digits = 2),
"<br><br>Ja-Stimmenanteil: ", round(data_graph_1$yes_share * 100, digits = 2), " %",
"<br>Nein-Stimmenanteil: ", round(data_graph_1$no_share * 100, digits = 2), " %"),
hoverinfo = "x+text",
marker = list(color = c("#EDD02E", "#CCCCCC", "#44187C")),
opacity = 0.8) %>%
add_bars() %>%
layout(title = "<b>Ja-/Nein-Stimmenanteil</b><br>je nach Vertrauen in Ministerpräsident Renzi",
xaxis = list(title = "Vertrauen in Ministerpräsident Matteo Renzi",
fixedrange = TRUE,
zeroline = FALSE),
yaxis = list(title = "Anteil Ja-/Nein-Stimmen<br>von -1 (100 % Nein-Stimmen) bis 1 (100 % Ja-Stimmen)<br> ",
fixedrange = TRUE),
font = list(family = "Work Sans"),
legend = list(traceorder = "normal",
orientation = "v"),
margin = list(l = 80,
r = 0,
t = 60,
b = 60,
pad = 0,
autoexpand = TRUE)) %>%
hide_legend() %>%
config(displaylogo = FALSE,
showLink = FALSE,
displayModeBar = FALSE)
Why doesn’t the hover text appear in the first case? Is this a bug? If a bug, is it already known to the devs? Otherwise I’d be happy to file an issue over at Github, just let me know!
I’m using plotly 4.5.6
in combination with R 3.3.2
.