[英]how to put two variables from a dataset on a bar graph stacked in R
I am trying to put two variables of a datatable in a bar chart (available and unavailable) in percentage (y axis) and Date in x axis for each service (color in the plotly to differentiate the services).我正在尝试将数据表的两个变量以百分比(y 轴)和 x 轴中的日期(plotly 中的颜色以区分服务)的百分比(y 轴)和日期的条形图(可用和不可用)中。 This is my datatable with respective variables.这是我的带有相应变量的数据表。 enter image description here在此处输入图像描述
And I am trying to combine these two variables in a single graph taking into account each service (Serie).考虑到每项服务(意甲),我试图将这两个变量组合在一个图表中。 At this moment I only got this: enter image description here此时我只得到这个:在此处输入图片描述
I tried to do this using plotly in R我尝试在 R 中使用 plotly 来做到这一点
barstack<-plot_ly(Servicelevel, x=Servicelevel$Date, y=Servicelevel$Available,
color=Servicelevel$Series,type = "bar")
barstack <- barstack %>% add_trace(y = Servicelevel$Unavailable)
barstack<-barstack %>%
layout(title = "Percentage of Availability over time",
yaxis = list(title = 'Availability (%)',
tickformat = ".2%"),
xaxis=list(title='Date'), barmode = 'stack')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.