I want to make an interactive needle plot using R package plotly similar as described here
By using ggplot2 and plotly, I could easily make an interactive needle plot:
library(ggplot2)
library(plotly)
p <- ggplot(data.frame(x=1:10, y=1:10),
aes(x=x, ymax=y, ymin=0)) +
geom_linerange()
ggplotly(p)
However, when the data size is too big, the above code to generate the needle plot become very slow.
I am wondering if I could make the needle plot directly using ggplotly.
Thanks a lot for your help.
>Solution :
You could use add_segments with specifying y = 0 like this:
library(dplyr)
library(plotly)
data.frame(x=1:10, y=1:10) %>%
plot_ly(data = .) %>%
add_segments(x=~x, xend = ~x, y = 0, yend=~y)

Created on 2023-04-05 with reprex v2.0.2
