简体   繁体   中英

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. 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). 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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