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.