Up x coordinate in horizontal barplot (R)

Hello,

I ask a question about how to change graphic elements position in the barplot of plotly package.

I want to change the display of the x coordinate

in barplot, moving from bottom to top, to enhance visualization.

The attached image explains better.

I wonder if it is possible, and if you can send me an example showing how to make.

If I understand correctly, something like this should achieve the desired result.

library(plotly)

mtcars %>%
  plot_ly() %>%
  add_bars(
    x=~mpg, y=~rownames(mtcars),
    orientation="h"
  ) %>%
  layout(
    xaxis=list(
      side='top'
    )
  )

If you are not yet using the development version of plotly, then you can just append the %>% layout(xaxis=list(side="top")) to your code and ignore the potentially confusing ~.

1 Like

Thank you, that was exactly what I wanted.