Невозможно отобразить как дискретные, так и недискретные данные на одной оси в графике r - PullRequest
0 голосов
/ 06 августа 2020

Мне нужно создать гистограмму с 4 категориями. Код, как показано ниже.

P <- plot_ly(type="bar")
l<-levels(data$s1)

for(i in 1:length(l)){
  #i=1
  d=data.frame(data[data$s1==l[i],])
  P <- add_trace(P, y=~Percentage, x=~bins,data=d,frame =~Year,
                 text = paste(l[i],d$count,'Total:',d$Total_count,sep = ':'),
                 name=l[i],marker = list(color = ifelse(l[i]=='type1' , "green",
                                                            ifelse(l[i]=='type2','red',
                                                                
                                                           ifelse(l[i]=='type3','orange','yellow')))))
  
}
P

Я получаю сообщение об ошибке, как показано ниже:

Error in which(idx)[[1]] : subscript out of bounds
In addition: Warning message:
Can't display both discrete & non-discrete data on same axis
...