R plot_ly错误:列`x`必须是长度1或4,而不是2

时间:2017-07-12 09:51:43

标签: r plotly

for this i错误:列x的长度必须为1或4,而不是2

library(plotly)
library(RColorBrewer)
coul = brewer.pal(4, "BuPu") 
Vertrag <- read.table(text =
'"Vert","Start","Ende"
"1","01.07.2017","31.03.2018"
"1","31.03.2018","30.06.2018"
"1","01.07.2018","31.03.2019"
"1","31.03.2019","30.06.2019"',
sep=',',header =T )
Vertrag$Start <- as.Date(Vertrag$Start, format ="%d.%m.%Y")
Vertrag$Ende <- as.Date(Vertrag$Ende, format ="%d.%m.%Y")
p <- plot_ly()
for(i in 1:(nrow(Vertrag))){
  p <- add_trace(p,
                 x = c(Vertrag$Start[i],Vertrag$Start[i] + difftime(Vertrag$Ende[i],Vertrag$Start[i], units = "days")),
             y = c(Vertrag$Vert),
             mode = "lines",
             line = list(color = colorRampPalette(coul)(10),width = 20))
}
p

但是当“Vertrag”只有两行时,它可以工作。

知道为什么和什么错了?

谢谢

奥拉夫

1 个答案:

答案 0 :(得分:1)

public List<MyObject> Items { get; set; } public string Filter { get { return filter; } set { filter = value; // Apply filter to list of Items here... } } 函数中的y轴从add_trace()更改为y = c(Vertrag$Vert)对我有用。

但我不确定这是你想要的情节。