Hi All,
I’ve created a grouped bar chart from tidy data, but am struggling with creating data labels for each individual bar within a group. All of the data labels seem to be at the correct x axis position, however, they are inline with the mid-point of each group.
This is my output,
I’ve tried changing the values for xref, x, xanchor, yref, y, and yanchor, however, have not seen the result I’d like, and have referenced, @Justin_Meyer 's, post, as this is the same question.
This is my current code,
p <- credInput() %>%
group_by(CredentialQ) %>%
plot_ly(x = ~vizCredPrcnt,
y = ~forcats::fct_reorder(CredentialQ, group_vizCredPrcntMean),
color = ~factor(year, ordered = TRUE),
colors = "RdYlBu",
type = "bar",
orientation = "h",
text = ~paste(round(vizCredPrcnt*100, 2), "%")) %>%
layout(xaxis = list(title = "Percent Held"),
yaxis = list(title = "Credentials"),
annotations = list(x = credInput()$vizCredPrcnt,
y = forcats::fct_reorder(credInput()$CredentialQ, credInput()$group_vizCredPrcntMean),
text = paste(round(credInput()$vizCredPrcnt * 100, 2), "%"),
xref = "x",
x = 0,
xanchor = "auto",
yref = "y",
y = 0,
yanchor = "auto",
showarrow = FALSE),
#margin parameter to show all y label text
margin = list(l = 160))
I’d greatly appreciate any insight, and many thanks!