Subplot failing in plotly

I am having the exact same issue at this. Subplots using Plotly - Failing to Coerce List to Double

Was this solved?

This works. The original example was trying to do something with the yaxis, but I think this needs to be done in layout(). The subplots command does not automatically create the subplots, if you read the documentation for it. You have to put the plots in a list then send the list to subplot()

library(plotly)

testData <- data.frame(
  timestamp = sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by="day"), 100, replace = TRUE),
  vessel = sample(LETTERS[1:4],  100, replace = TRUE),
  reading = floor(runif(100)*60-10),
  id = sample(1:4,  100, replace = TRUE))

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

Thanks for the reply, I am still getting the same error. The timestamps are like this


Is the error due to the presence of milliseconds?

Here is my full code

df <- read_delim("data.TXT",
"\t", escape_double = FALSE, col_types = cols(a = col_time(format ="%H:%M:%OS")),
trim_ws = TRUE, skip = 6)

df.new <- df[,colSums(is.na(df))<nrow(df)] %>%
tidyr::gather(variable, value, -a) %>%
transform(id = as.integer(factor(variable)))

df.new$variable<- factor(df$variable, levels = names(df[ncol(df):2]))

p <- plot_ly(data=df.new,x = ~a, y = ~value, color = ~variable,
colors = "Dark2",yaxis = ~paste0( "y",sort(id, decreasing =F)))%>%
add_lines() %>%
subplot(nrows = length(df)-1, shareX = TRUE)

Please read my answer.

Thank you, I have figured it out. The issue was in the nrows argument in the subplot command.It should be
subplot(nrows = length(unique(df.new$variable)), shareX = TRUE)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.