How do you add a customized color index for mesh3d plots in Plot_ly?
我可以轻松地在R中绘制
1 2 3 4 5 | library(plotly) x <- runif(50, 0, 110) y <- runif(50, 0, 1) z <- runif(50, 1, 2) plot_ly(x = ~x, y = ~y, z = ~z, type = 'mesh3d') |
我想基于
我已经使用
1 2 3 4 5 6 7 8 9 10 11 | library(lattice) x<-runif(12,0,1) y<-runif(12,0,2) grid<-expand.grid(x,y) z<-grid$Var1 + grid$Var2^2 df<-data.frame(z=z,x=grid$Var1,y=grid$Var2) # Note: there are 144 observations and I want 6 colors, so I need 144/6 = 24 replications for each color nrow(df) nrow(df)/6 a<-palette(c(rep("blue",24),rep("light blue",24),rep("green",24),rep("yellow",24),rep("orange",24),rep("red",24))) wireframe(z~x + y,data=df,drape=T,col.regions=a) |
欢迎来到SO!
您可以像这样添加自定义colorRamp:
1 2 3 4 5 6 | library(plotly) x <- runif(50, 0, 110) y <- runif(50, 0, 1) z <- runif(50, 1, 2) plot_ly(x = ~x, y = ~y, z = ~z, intensity = ~z, type = 'mesh3d', colors = colorRamp(c("blue","lightblue","chartreuse3","yellow","red"))) |