title: How to change legend position in ggplotly in R
body: <p>The below code generates two plots using <code>ggplot</code> and <code>ggplotly</code>. Despite of using the <code>layout()</code> to ggplotly the legend is still at the right side. The legend is required to be at the bottom. Could anyone help to move the legend to bottom in the ggplotly? I have tried the solution at <a href="https://stackoverflow.com/questions/69306154/r-shiny-plotly-ggplotly-moves-the-legend-to-the-right">R + shiny + plotly: ggplotly moves the legend to the right</a> and is not working here. Can someone help if im missing the obvious.</p>
  <pre><code>measure&lt;-c(&quot;MSAT&quot;,&quot;MSAT&quot;,&quot;GPA&quot;,&quot;MSAT&quot;,&quot;MSAT&quot;,&quot;GPA&quot;,&quot;GPA&quot;,&quot;GPA&quot;)
  score&lt;-c(500, 490, 2.9, 759, 550, 1.2, 3.1, 3.2)
  data&lt;-data.frame(measure,score)
  
  
  ui &lt;- fluidPage(
    mainPanel(
      plotOutput(&quot;myplot&quot; ),
      plotlyOutput(&quot;myplot2&quot; )
    )
  )
  
  server &lt;- function(input, output) {
    myplot &lt;- reactive({
      gpl1 &lt;- ggplot(data,aes(y=reorder(measure, score),x=score,fill=score)) +
        geom_bar(stat=&quot;identity&quot;)+
        theme(legend.position=&quot;bottom&quot;)+
        xlab(&quot;x&quot;)+
        ylab(&quot;y&quot;)+
        labs(title = NULL)
      gpl1
    })
    
    myplot2 &lt;- reactive({
      gpl2 &lt;- ggplot(data,aes(y=reorder(measure, score),x=score,fill=score)) +
        geom_bar(stat=&quot;identity&quot;) +
        theme(legend.position=&quot;bottom&quot;)+
        xlab(&quot;x&quot;)+
        ylab(&quot;y&quot;)+
        labs(title = NULL)
      ggplotly(gpl2) %&gt;% 
        layout(legend = list(orientation = 'h', x = 0.45, y = 1.1))
    })
    output$myplot &lt;- renderPlot({
      myplot()
    })
    output$myplot2 &lt;- renderPlotly({
      myplot2()
    })
  }
    
  shinyApp(ui = ui, server = server)
  </code></pre>