Ordered bars on plotly

╄→尐↘猪︶ㄣ 提交于 2019-12-13 02:35:52

问题


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...


回答1:


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



来源:https://stackoverflow.com/questions/51090010/ordered-bars-on-plotly

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