Skip to content

Changing the DayofYear hover over from ggplot to Plotly? #544

Closed
@ahsanshah

Description

@ahsanshah

I must be missing something as this should be fairly simple. I have a ggplot for which I have multiple years of data. I needed the data across multiple years to "overlap" on the same plot. The fact that 2016 is a leap year causes issues on the X axis scaling. I looked to see if there was any package or solution but was unable to find anything. As such, I rescaled across LEAP and NON LEAP to have a DAY range of 366 (versus 365 for 2 years and 366 for 2016).

This is all working fine. Howwver, I now want to force PLOTLY to show the DATE value on the Hover over versus the X axis DayofYear. I assumed I can easily overwrite this using something like this which I found.

p_gg_build <- plotly_build(p1)
p_gg_build$data[[2]]$text <- paste("DATE = ", test_tmp$DT_STAY_DATE)

However, this applied to a specific trace (e.g. trace #2). Is there no way to automatically force all traces to have the custom HOVER over? Essentially, how do I force ALL traces to overwrite the custom HOVER text? Is there a simpler option that can allow me to overwrite the ggplot hover text?

Attached code and RDS files for reference.

Support.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions