title: R Plotly -Stacked Barchart with total amount of bars text
body: <p><strong>Problem:</strong> I have a stacked barchart. Above each of the stacked bars I want to have a total number (i.e. the sum of the two bars - here: <code>total</code>). I tried to take usage of <code>add_text</code> but it did not work out as expected. Any suggestions what to change?</p>
  
  <p><strong>Remark:</strong> I do not want to cast the <code>data.table</code> object. The target frame on which the visualizations shall be made is <code>new_frame</code>.</p>
  
  <p>Many thanks</p>
  
  <p><a href="https://i.stack.imgur.com/FdBki.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FdBki.png" alt="enter image description here"></a></p>
  
  <pre><code>library(data.table)
  library(plotly)
  
  Animals &lt;- c("giraffes", "orangutans", "monkeys")
  SF_Zoo &lt;- c(20, 14, 23)
  LA_Zoo &lt;- c(12, 18, 29)
  data &lt;- data.table(Animals, SF_Zoo, LA_Zoo)
  
  new_frame &lt;- data.table::melt(data, id.vars='Animals')
  
  new_frame[, total := sum(value), by = Animals]
  
    plot_ly(new_frame, x = ~Animals, 
            y = ~value, 
            type = 'bar', 
            name = ~variable,
            hoverinfo = "text",
            text = ~paste(variable, value, total)) %&gt;%
  ## Not working
      add_text(x = ~Animals, y = ~value,
               text = ~total, textposition = "top center") %&gt;%
    layout(yaxis = list(title = 'Count'), barmode = 'stack')
  
  
  </code></pre>