Subplot Failing - List Object Cannot Be Coerced to Double

I am trying to generate multiple plots without having to create a plot for each line. I’m using the subplot function and following the example from this page.

The structure of my data is as follows:

timestamp vessel reading id
2019-01-02 09:00:00 pre_ac_1 54 5
2019-01-02 09:00:00 post_ac_1 58 3
2019-01-02 09:00:00 ac_dif_1 -4 1
2019-01-02 09:00:00 pre_ac_2 52 6
2019-01-02 09:00:00 post_ac_2 50 4
2019-01-02 09:00:00 ac_dif_2 2 2
2019-01-03 09:00:00 pre_ac_1 56 5
2019-01-03 09:00:00 post_ac_1 60 3

The data is stored in a tibble. The timestamp columns is a POSIXct object, vessel is chr, reading is dbl, and id is int.

Here’s the code I’m using to create the plot:

test_plot <- plot_ly(testData, x = ~timestamp, y = ~reading, 
                     color = ~vessel, colors = "Dark2",
                     yaxis = ~paste0("y", id))
test_plot <- test_plot %>% add_lines()
test_plot <- test_plot %>% subplot(nrows = 6, shareX = TRUE)

When I run this, I get the following error message:

I’ve tried turning the timestamp into a Date class using as.Date() and turning the tibble into a data.frame so it matches the structure described in the example I linked at the beginning. Lastly, if I exclude the subplot line, I get a single plot with all the lines plotted on it.

@s-etty did you ever find a solution to this issue?

I’m having a similar problem even though the same script was working 24 hours ago…

For others that might come across this thread - I was able to solve my problem but not without having to slap myself for stupidity.

Between sessions working with plotly, I had installed a package called Hmisc that contains a subplot() function unrelated to plotly. I ended up loading Hmisc after plotly in my script so R was using Hmisc::subplot() instead of plotly::subplot. Happily my script works again after specifying plotly::subplot. As an alternative, I could’ve just switched the order in which I loaded my packages. The issue was a nice reminder to check the console output every once in a while…