'Plotly/Vistime - overlapping labels

I have a simple timeline I've built using Vistime/Plotly:

library(vistime)
library(plotly)
data <- read.csv(text="event,group,start,end,color
                       Bought Apples,Shopping,2020-06-15,2020-10-15,#fed8b1 
                       Shoes,Shopping,2020-07-01,2020-07-01,#fed8b1 
                       Shoes,Shopping,2020-07-01,2020-07-01,#fed8b1 
                       Shoes,Shopping,2020-07-02,2020-07-02,#fed8b1
                       Shirts,Shopping,2020-07-01,2020-07-01,#fed8b1 
                       Invoice,Charity,2020-08-30,2020-08-30,#fed8b1 
                       Report 1,Work,2020-06-10,2020-06-10,#ffcccb  
                       Meeting 5,Meetings,2020-08-15,2020-08-15,#b19cd9  ")



p <- vistime(data)
pb <- plotly_build(p)

#change label size
for (i in 1:length(pb$x$data)) {
  if (pb$x$data[[i]]$mode == "text") pb$x$data[[i]]$textfont$size <- 10
}

#change x axis font size:
#pb$x$layout$xaxis$tickfont <- list(size = 28)

# change marker size
for (i in 1:length(pb$x$data)) {
  if (pb$x$data[[i]]$mode == "markers") pb$x$data[[i]]$marker$size <- 20
}
pb

Which gives me:

enter image description here

As you can see, if there are multiple points clustered close together, the labels collide. Is there any fairly easy way to avoid this problem? An out-of-the box solution that isn't too complex? I'm wondering if there's any built in methods in Vistime or Plotly to deal with this.



Solution 1:[1]

Unfortunately, Plotly has no option to avoid these overlapping labels (or maybe I just don't know about one). However, using gg_vistime() and hc_vistime() these overlaps are avoided automatically:

gg_vistime(data)

gg_vistime

hc_vistime(data)

enter image description here

Documentation:

https://cran.r-project.org/web/packages/vistime/vignettes/gg_vistime-vignette.html

https://cran.r-project.org/web/packages/vistime/vignettes/hc_vistime-vignette.html

Disclaimer: I wrote this package

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shosaco