0
votes

Is it possible to add vertical line to a boxplot in plotly? I know it works in ggplot2, but I need it in plotly. Would be nice if I don't need to convert my static ggplot every time.

Here is a minimal example

plot_ly(x = ~rnorm(50), type = "box") %>% 
   add_trace(x = ~c(0.75),y=c(-2,0.5),type='scatter',mode='lines')

Instead of the line stoping before I want the line to go through the boxplot. In addition I want the same plot extent as the single boxplot.

1
I tried setting a value for the y-axis of the box-plot, but then my boxplot didnt appear anymore5th

1 Answers

1
votes

Change the sequence of calls:

library(plotly)
plot_ly(x = ~c(0.75), y=c(-2,2), type='scatter', mode='lines') %>% 
  add_boxplot(x = ~rnorm(50), inherit = F) %>% 
  layout(yaxis = list(range = c(-2, 2))) 

enter image description here