2

I have an R shiny application and on one page I have a scatter plot with about 100 markers. My goal is to add a label to each marker as explained here https://plotly.com/r/text-and-annotations/ It kind of words but the problem is that the text of each marker overlaps most of the time with text of other markers. After some research, I learned there are packages like ggrepel https://ggrepel.slowkow.com/articles/examples.html that help fix this problem. However, if I try to eventually reconvert the ggplot to plotly the text labels disappear. I will show you an example:

df <- data.frame(xvals = rnorm(1:100), yvals = rnorm(1:100), label_var = paste0("label_",  as.character(round(rnorm(1:100),3))))
p <- ggplot(df, aes(xvals, yvals, label = label_var)) +  geom_point(color = "red")
p2 <- p + geom_text_repel() + labs(title = "geom_text_repel()") # visualize this plot. it's perfect
p3 <- plotly_build(p2) # visualize now p3, you see the labels have disappeared

what can I do to visualize in my shiny app a plot as displayed in p2? Thanks

Angelo
  • 1,594
  • 5
  • 17
  • 50
  • 1
    I'm afraid `plotly` does not support `geom_text_repel`. You should get a warning about that. – stefan Jan 13 '21 at 20:54
  • @stefan is right! Indeed running your code shows that the ggrepel is not yet implemented in plotly – Duck Jan 13 '21 at 20:59
  • @stefan Ok but does that mean there's no available solution for plotly? It's ok if I have to use different code and packages, I would just need a way to avoid overlapping. Thoughts? – Angelo Jan 13 '21 at 21:12
  • Hi Angelo. Unfortunately no. ): I don't know of any other package like `ggrepel`. And even if there is any I would guess that you would run into the same issue. – stefan Jan 13 '21 at 21:45
  • Understood, many thanks Stefan for looking into this – Angelo Jan 13 '21 at 22:24

0 Answers0