【问题标题】:Ordered bars on plotlyplotly 上的有序条形图
【发布时间】:2018-12-07 22:57:39
【问题描述】:

我正在尝试使用 Plotly 和 R 制作 CPU 使用率图表,我希望最大使用率(100%,蓝色条)在顶部,另一个在底部,但是当我尝试此代码时

     plot_ly( x = cores, y = max, type = 'bar', name = 'Free') %>%
       add_trace( y = data, name = 'Used') %>%
       layout(
         title = "CPU Usage",
         font = list(family = 'Comic Sans MS'),
         yaxis = list(title = 'Percent'),
         xaxis = list(title = '', tickangle = -45),
         barmode = 'stack')
   })

它给了我相反的顺序,将较大的条放在底部,橙色的条放在顶部。我想反转它。

我搜索了一些references,但没有找到任何相关内容...

【问题讨论】:

    标签: r plotly r-plotly


    【解决方案1】:

    我们不知道您的数据,但是:

    cores <- c("Average", "Core1", "Core2", "Core5")
    Free <- c(65, 60, 80,50)
    Used <- c(100-65, 40, 20,50)
    data <- data.frame(cores, Free, Used)
    
    plot_ly(data, x = ~cores, y = ~Used, type = 'bar', name = 'Used') %>%
      add_trace(y = ~Free, name = 'Free') %>%
      layout(yaxis = list(title = '%'), barmode = 'stack')
    

    【讨论】:

      猜你喜欢
      • 2021-12-28
      • 1970-01-01
      • 1970-01-01
      • 2021-11-05
      • 2021-07-13
      • 2017-03-02
      • 1970-01-01
      • 2016-02-25
      • 1970-01-01
      相关资源
      最近更新 更多