R plotly hover label text alignment

删除回忆录丶 提交于 2019-12-08 18:17:45

问题


I'm adding custom hover text for scatterplot points in a plotly graph in R. It appears to be aligning the text left, center, or right depending on whether the text box is shown to the right, center, or the left of the plot points, respectively. I'd prefer if the text was always aligned left regardless of the positioning of the box. I've been able to style the font, e.g. setting the color and size, but haven't been able to change the text alignment.

Here's an MRE. I've removed the legend so the points on the far right are forced to have their hover boxes appear to the left of the point.

plot_ly(iris,
        x = ~Sepal.Length,
        y = ~Sepal.Width,
        type = 'scatter',
        mode = 'markers',
        hoverinfo = 'text',
        hoverlabel = list(font = list(color = 'white')),
        text = ~paste0('Some rather long text',
                       '\nSepal.Length: ', Sepal.Length,
                       '\nSepal.Width: ', Sepal.Width)) %>%
  layout(showlegend = FALSE)


回答1:


This is now controllable via the layout.hoverlabel.align attribute: https://plot.ly/r/reference/#layout-hoverlabel-align



来源:https://stackoverflow.com/questions/50003531/r-plotly-hover-label-text-alignment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!