情节上有序的酒吧 [英] Ordered bars on plotly

查看:95
本文介绍了情节上有序的酒吧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Plotly和R创建一个CPU使用情况图,我想在顶部使用最大使用率(100%,蓝色条),在底部使用另一个使用率,但是当我尝试此代码时

I'm trying to make a CPU Usage graph with Plotly and R, I want the max usage (100%, the blue bar) on top, and the other one on bottom, but when I try this code

     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')
   })

它给了我相反的效果,在底部排列较大的条,在顶部排列橙色的条.我要反转它.

It gives me the reverse, ordering the greater bar on bottom, and the orange one on top. I want to invert it.

我搜索了一些参考,但是什么也没有被发现有关...

I searched on some references but nothing was found about that...

推荐答案

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

We do not know your data but:

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

这篇关于情节上有序的酒吧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆