【问题标题】:Display X Axis at Top of Plotly Plot in R Shiny Instead of Bottom?在R Shiny而不是底部的绘图顶部显示X轴?
【发布时间】:2017-05-17 20:37:25
【问题描述】:

如何在 Plotly 水平条形图的顶部而不是底部显示 x 轴?在顶部和底部显示 x 轴也可以。该图将以 R Shiny 显示,并且必须是 Plotly 而不是 ggplotly。谢谢!

来自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')

编辑:HubertL 提供了一个解决方案(谢谢!),将 x 轴放在顶部,但随后与图表标题重叠。我没有指定我正在使用标题是我的错。有没有办法让 x 轴标题和 x 轴刻度不与绘图标题重叠?

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

【问题讨论】:

    标签: r shiny plotly


    【解决方案1】:

    您可以在layout.xaxis 中使用side ="top"

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

    【讨论】:

    • 谢谢!这将 x 轴向上移动。我很高兴将其标记为已回答,但它并不适合我。当我使用您的解决方案时,绘图标题、x 轴标题和 x 轴刻度重叠。我会更具体地编辑我的问题 - 如果这不是我应该做的,请告诉我。
    • 好!所以请将其标记为已回答并提出另一个问题
    • 要增加绘图上方的空间并避免标题重叠,请将margin 添加到layout,例如。 margin=list(t=150, l=100)
    猜你喜欢
    • 1970-01-01
    • 2020-05-19
    • 1970-01-01
    • 2016-10-20
    • 1970-01-01
    • 2014-07-15
    • 1970-01-01
    • 1970-01-01
    • 2018-09-09
    相关资源
    最近更新 更多