Skip to content

geom_label() in plotly #546

Closed
Closed
@lindsayrutter

Description

@lindsayrutter

Thank you for such a useful and user-friendly package!

I recently tried to use plotly for a ggplot2 object that had geom_label(). I received a warning message that geom_label() has yet to be implemented in plotly, and to post an example code here for any geom that may be useful to be implemented.

library(ggplot2)
library(plotly)

dat=data.frame(label=paste0("label",seq(1:5)), xstart = seq(10,50, by=10), ystart = seq(1:5)+.1, xend = c(seq(20,50, by=10), 50), yend = c(seq(1:4)+.9, 5.1), x = seq(10,50, by=10), y=seq(1:5))

myPlot = ggplot2::ggplot(data = dat,ggplot2::aes(x = x, y = y, label=label)) +
  ggplot2::geom_segment(ggplot2::aes(x=xstart, y=ystart, xend=xend, yend=yend)) +
  ggplot2::geom_label(fill = "grey80", size = 3) +
  ggplot2::scale_x_continuous(expand = c(.1, .1))

ggplotly(myPlot, tooltip = c("x", "label"))

The static myPlot object itself has five labels, labeled as "label1", "label2", "label3", "label4", and "label5" with x values of 10, 20, 30, 40, and 50. I was aiming for the last line to allow the interactive tooltip to show the label and x values for each of the five labels. Instead, it seems, upon running the last line, that the geom_labels disappear, and upon hovering over, the interactivity is on the values at the corners of the edges from the geom_segment().

I just wanted to post it here in case it is of something of interest to the developers or others. Thank you!

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