Display X Axis at Top of Plotly Plot in R Shiny Instead of Bottom?

倖福魔咒の 提交于 2019-12-24 01:54:12

问题


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")


回答1:


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" ) ) 



来源:https://stackoverflow.com/questions/44034368/display-x-axis-at-top-of-plotly-plot-in-r-shiny-instead-of-bottom

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!