简体   繁体   English

ggplotly - Hover 文本关闭 plot 在固定位置

[英]ggplotly - Hover text off plot in fixed location

Using ggplotly I am attempting to have the content of the hovertext box dynamically change with the mouse cursor, but have a fixed position off of the plot.使用 ggplotly 我试图让悬停文本框的内容随着鼠标 cursor 动态变化,但在 plot 上有一个固定的 position。 I have attempted to adjust the 'hoverlabel' using the layout function, but have had no success considering there is no option to edit position (other than alignment).我尝试使用布局 function 调整“悬停标签”,但考虑到没有编辑 position 的选项(对齐除外),因此没有成功。 Is there a good way to do this?有没有好的方法来做到这一点? Thanks!谢谢!

Here is my code so far:到目前为止,这是我的代码:

  p1 <- ggplotly(p1, tooltip = c("team")) %>%

    config(displayModeBar = F, doubleClick = F, scrollZoom = F, doubleClickDelay = F) %>% layout(xaxis=list(fixedrange=TRUE, showspikes = TRUE, spikemode = 'toaxis+across+marker', spikesnap = 'hovered data+data+cursor', showline = TRUE, spikecolor = 'black',
                                                                                                            spikedash = 'solid')) %>% layout(yaxis=list(fixedrange=TRUE)) %>% layout(spikedistance = -1) %>%
    layout(hoverlabel = list(bgcolor = 'white',   font = list(family = 'Source Sans Pro'))) %>%
    layout(hovermode = "x") %>% layout(font = list(family = 'Source Sans Pro')) %>%
    layout(legend = list(font = list(family = 'Source Sans Pro'))) %>%
    onRender("function(el,x){el.on('plotly_legendclick', function(){ return false; })}")

I found an solution using the same method in this github: https://github.com/ropensci/plotly/blob/master/demo/custom-javascript.R我在此 github 中找到了使用相同方法的解决方案: https://github.com/ropensci/plotly/blob/master/demo/custom-javascript.ZE1E1D3D40573127E9EE0480CAF18

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM