title: R: Disappearing Graphs
body: <p>I am using the R programming language. Using the following code, I made these interactive time series graphs:</p>
  <pre><code>library(dplyr)
  library(ggplot2)
  library(shiny)
  library(plotly)
  library(htmltools)
  
  library(dplyr)
  #generate data
  set.seed(123)
  
  ######
  
  var = rnorm(731, 85,25)
  date= seq(as.Date(&quot;2014/1/1&quot;), as.Date(&quot;2016/1/1&quot;),by=&quot;day&quot;)
  data = data.frame(var,date)
  
  vals &lt;- 90:100
  combine &lt;- vector('list', length(vals))
  count &lt;- 0
  for (i in vals) {
      
      data$var_i = i
      data$new_var_i = ifelse(data$var &gt;i,1,0)
      
      #percent of observations greater than i (each month)
      aggregate_i = data %&gt;%
          mutate(date = as.Date(date)) %&gt;%
          group_by(month = format(date, &quot;%Y-%m&quot;)) %&gt;%
          summarise( mean = mean(new_var_i))
      
      #combine files together
      
      aggregate_i$var = i
      aggregate_i$var = as.factor(aggregate_i$var)
      
      count &lt;- count + 1
      combine[[count]] &lt;- aggregate_i
      
  }
  
  
  result_2 &lt;- bind_rows(combine)
  result_2$group = &quot;group_b&quot;
  result_2$group = as.factor(result_2$group)
  
  a = result_2 %&gt;%
    plot_ly(x=~month, y=~mean, color=~group) %&gt;%
    group_by(group) %&gt;%
    add_lines(frame=~var,hoverinfo = &quot;text&quot;,
              text = ~ paste0(&quot;Month: &quot;,month, &quot;&lt;br&gt;&quot;,
                              &quot;Mean: &quot;, mean, &quot;&lt;br&gt;&quot;,
                              &quot;Total: &quot;, mean(mean))) %&gt;%
    layout(title = list(text = &quot;title&quot;),
           xaxis = list(tickangle = -90, tickformat = &quot;%m-%Y&quot;))
  
  
  
  ######
  
  
  var = rnorm(731, 75,2)
  date= seq(as.Date(&quot;2014/1/1&quot;), as.Date(&quot;2016/1/1&quot;),by=&quot;day&quot;)
  data = data.frame(var,date)
  
  vals &lt;- 75:80
  combine &lt;- vector('list', length(vals))
  count &lt;- 0
  for (i in vals) {
      
      data$var_i = i
      data$new_var_i = ifelse(data$var &gt;i,1,0)
      
      #percent of observations greater than i (each month)
      aggregate_i = data %&gt;%
          mutate(date = as.Date(date)) %&gt;%
          group_by(month = format(date, &quot;%Y-%m&quot;)) %&gt;%
          summarise( mean = mean(new_var_i))
      
      #combine files together
      
      aggregate_i$var = i
      aggregate_i$var = as.factor(aggregate_i$var)
      
      count &lt;- count + 1
      combine[[count]] &lt;- aggregate_i
      
  }
  
  
  result_3 &lt;- bind_rows(combine)
  result_3$group = &quot;group_b&quot;
  result_3$group = as.factor(result_3$group)
  
  b = result_3 %&gt;%
    plot_ly(x=~month, y=~mean, color=~group) %&gt;%
    group_by(group) %&gt;%
    add_lines(frame=~var,hoverinfo = &quot;text&quot;,
              text = ~ paste0(&quot;Month: &quot;,month, &quot;&lt;br&gt;&quot;,
                              &quot;Mean: &quot;, mean, &quot;&lt;br&gt;&quot;,
                              &quot;Total: &quot;, mean(mean))) %&gt;%
    layout(title = list(text = &quot;title&quot;),
           xaxis = list(tickangle = -90, tickformat = &quot;%m-%Y&quot;))
  
  ##### https://stackoverflow.com/questions/66180563/r-updating-hover-text
  
  
   a = plot_ly(result_2, x=~month, y=~mean, color=~group) %&gt;%
    group_by(group) %&gt;%
    add_lines(frame=~var,hoverinfo = &quot;text&quot;,
              text = ~ paste0(&quot;Month: &quot;,month, &quot;&lt;br&gt;&quot;,
                              &quot;Mean: &quot;, mean, &quot;&lt;br&gt;&quot;,
                              &quot;Total: &quot;, mean(mean))) %&gt;%
    layout(title = list(text = &quot;title1&quot;),
           xaxis = list(tickangle = -90, tickformat = &quot;%m-%Y&quot;))
  
  
  b = plot_ly(result_3, x=~month, y=~mean, color=~group) %&gt;%
    group_by(group) %&gt;%
    add_lines(frame=~var,hoverinfo = &quot;text&quot;,
              text = ~ paste0(&quot;Month: &quot;,month, &quot;&lt;br&gt;&quot;,
                              &quot;Mean: &quot;, mean, &quot;&lt;br&gt;&quot;,
                              &quot;Total: &quot;, mean(mean))) %&gt;%
    layout(title = list(text = &quot;title2&quot;),
           xaxis = list(tickangle = -90, tickformat = &quot;%m-%Y&quot;))
  
  #view plots
  
  a
  
  b
  </code></pre>
  <p>These two graphs work fine when you view them individually:</p>
  <p><a href="https://i.stack.imgur.com/C3RoB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C3RoB.png" alt="enter image description here" /></a></p>
  <p>But when I try to use the <code>plotly::subplot()</code> command, the second graph disappears:</p>
  <pre><code>subplot(a,b, nrows=1)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/qM9eV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qM9eV.png" alt="enter image description here" /></a></p>
  <p>Does anyone know why this is happening and is there a way to fix this? Is there also a way to use the <code>ggplot2::facet_wrap()</code> command in this instance to &quot;synchronize&quot; both graphs together (like here: <a href="https://stackoverflow.com/questions/66129000/r-tie-two-graphs-together">R: &quot;tie&quot; two graphs together</a>) ?</p>
  <p>Thanks</p>