4
一個客戶要我做像this一個陰謀。該引用使用rgl-package,但導出數字的質量太低。於是,我開始情緒低落。我可以管理大部分我想做的事情,但出於某種原因,所有酒吧都有不同的顏色。顏色在plotly
一個MWE:
X<-1:60
Y<-sort(runif(60,-3,3))
Z<-runif(60,0,50)
p<-plot_ly(x = c(X[1],X[1]+1,X[1]+1,X[1]),
y = c(0,0,Y[1],Y[1]), z=c(0,0,0,0),type = "mesh3d",color=I("red"))
for(i in X){p<-add_trace(p,x = c(i,i+1,i+1,i),
y = c(0,0,Y[i],Y[i]), z=c(0,0,0,0),type = "mesh3d",color=I("red"))}
for(i in X){p<-add_trace(p,x = c(i,i+1,i+1,i),
y = c(0,0,0,0), z=c(0,0,Z[i],Z[i]),type = "mesh3d",i=c(0,0),
j=c(1,2),k=c(2,3),color=I("black"))}
p
什麼實際上,我尋找的是類似於下面的東西,用每個因子水平的顏色,但現在,結果與上面的相同:
X<-1:60
Y<-sort(runif(60,-3,3))
Z<-runif(60,0,50)
ColFactor<-sample(c(0,1),60,replace = TRUE)
p<-plot_ly(x = c(X[1],X[1]+1,X[1]+1,X[1]), y = c(0,0,Y[1],Y[1]), z=c(0,0,0,0),
type = "mesh3d",color=ColFactor,colors=c("red","blue"))
for(i in X){p<-add_trace(p,x = c(i,i+1,i+1,i), y = c(0,0,Y[i],Y[i]), z=c(0,0,0,0),
type = "mesh3d",color=ColFactor,colors=c("red","blue"))}
for(i in X){p<-add_trace(p,x = c(i,i+1,i+1,i), y = c(0,0,0,0), z=c(0,0,Z[i],Z[i]),
type = "mesh3d",i=c(0,0),j=c(1,2),k=c(2,3),color=I("black"))}
p