Skip to content
  • Hi Pawel,

    This is very helpful, and works wonderfully! I am reordering the scatterplot in an ascending order in my ggplot. The tooltip however, does not get rearranged. How can I fix that?

    Here is my code:

    losd <- ggplot(lo_sd, aes(x = uid, y = bc, color = color)) + geom_point(aes(x = reorder(lo_sd$uid, lo_sd$bc), y = lo_sd$bc), size=2) + geom_errorbar(aes(ymin = lo_sd$lci, ymax = lo_sd$uci), width=0.00, show_guide = F, size = 1) + geom_hline(yintercept = 0, linetype="solid", color = "#6b5e4f", size=1) + scale_y_continuous(limits = c(-0.65, 0.65)) + scale_x_discrete(limits = lo_sd$uid, labels = lo_sd$cname) + scale_color_discrete(name = "Subject tests") + labs(y = "Effect size (sd)", x = "", title = "") + coord_flip()

    Any thoughts?

    Thanks you so much!

  • Hi Pawel,

    I would like to use nearPoints on a ggplot map. I was planning on using something like the attached shiny app:

    app.R

    However, it is clear that nearPoints is off. It seems to be more off in the top left than the bottom right.

    changing the projection from

    coord_map("polyconic" ) to coord_map() makes the difference smaller, but it still exists.

    Do you have any insights on how to read the appropriate nearPoint?

  • Hi Pawel, I've used your script inside the output$hover_info code block above quite successfully to customise the information inside the mouse hovers on a ggplot chart. However in my second shiny app, the same hoverbox flickers several times before stabilizing. I have tried on many points - even non overlapping points. No matter how clean the point is, the hover box flickers and shows the same information inside it every time. So there is no jumping of points. Seems the show/hide of the box goes into a loop somewhere in the underlying code. It's beyond my capability to troubleshoot this. Have searched the net and found several references. This one here seems to be the solution to the problem I have but it talks in CSS/bootstrap language and I do not know how to import this in shiny code. Any help would be appreciated.

  • madelhorius @madelhorius ·

    @sanjmeh I had the same flickering issue. You need to add a style argument to uiOutput:

    uiOutput("hover_info", style = "pointer-events: none")

    This solved the flickering issue in my ShinyApp.

  • This has a bug on certain monitor resolutions. Depending on how shiny scales the image size, you may see the tooltip move twice as far as the mouse moves, like so:

    In this example, the mouse is swinging around a plot and the tooltip is far away from the mouse cursor. Quite broken.

    Instead of computing the tooltip pixel position yourself,

        # calculate point position INSIDE the image as percent of total dimensions
        # from left (horizontal) and from top (vertical)
        left_pct <- (hover$x - hover$domain$left) / (hover$domain$right - hover$domain$left)
        top_pct <- (hover$domain$top - hover$y) / (hover$domain$top - hover$domain$bottom)
        
        # calculate distance from left and bottom side of the picture in pixels
        left_px <- hover$range$left + left_pct * (hover$range$right - hover$range$left)
        top_px <- hover$range$top + top_pct * (hover$range$bottom - hover$range$top)

    you can instead use the hover api's css coordinates:

        left_px <- hover$coords_css$x
        top_px <- hover$coords_css$y

    This fixes the bug and is much more concise.

    Edited by Cypress Frankenfeld
  • I had the flickering issue, too. @cypressf's suggestion, although irrelevant it seems, helps fixed the issue.

  • This is a great solution, thanks for providing the code! It works really well but it seems not all points in my scatter return a value when hovering over it. My scatter is a little more complex with two groups, but for both groups it works for some points, for others not. Any support is highly appreciated. My code and data is attached.MeasureHover.RDummyDataHover.csv

    Edited by Martin Weltring
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment