I am working on a visualization with a bar trace representing a duration taken and a scatter trace representing a score of a test, where I would like custom text annotating the scatter trace, rotated 270 degrees within the bar, showing the score, e.g. “5 points”.
My current code, below, allows me to do everything but rotate the text, and I cannot find anything in the documentation that will allow the custom text AND the text rotation. I’ve attempted add_annotation() which allows rotation via the textangle argument, but had trouble with the custom text aspect.
data %>%
plot_ly() %>%
add_trace(x = ~person, y = ~time, type = 'bar', showlegend = F) %>%
add_trace(x = ~person, y = ~score, type = 'scatter', mode = 'markers+text',
marker = list(color = 'rgb(255, 255, 255)', size = 5), texttemplate = "%{y} points",
textposition = 'top center', showlegend = F) %>%
layout(title = "title",
yaxis = list(title = 'Time (seconds)'),
xaxis = list(title = '', categoryorder = "total ascending"),
hovermode = "compare")
Surely this something I can do with plotly in R. If anyone could walk me through a solution I’d greatly appreciate it. Thanks!