How do I display the x axis at the top of a Plotly horizontal bar plot instead of at the bottom? Showing the x axis at both the top and bottom would also be ok. The plot will be displayed in R Shiny and must be Plotly not ggplotly. Thanks!
Example from https://plot.ly/r/horizontal-bar-charts/:
library(plotly)
plot_ly(x = c(20, 14, 23), 
y = c('giraffes', 'orangutans', 'monkeys'), 
type = 'bar', 
orientation = 'h')
EDIT: HubertL provided a solution (thanks!) that puts the x axis at the top but it then overlaps with the chart title. My fault for not specifying that I am using a title. Is there a way to get the x axis title and x axis ticks to not overlap the plot title?
plot_ly(x = c(20, 14, 23), 
        y = c('giraffes', 'orangutans', 'monkeys'), 
        type = 'bar', 
        orientation = 'h') %>%
   layout(xaxis = list(side ="top", 
          title = "EXAMPLE X AXIS TITLE"), 
          title = "EXAMPLE PLOT TITLE")

You can use side ="top" in the layout.xaxis
plot_ly(x = c(20, 14, 23), 
        y = c('giraffes', 'orangutans', 'monkeys'), 
        type = 'bar', 
        orientation = 'h') %>%
  layout(xaxis = list(side ="top" ) ) 

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With