Reputation: 349
I am trying to use plot_ly function for 3D plot in R
I have constant date variable in my data which made the plot disappear
In the code below you can see that this problem shows up only with constant date variable
#date constant variable
data<-data.frame(x=c(1,2,3,4,5),y=rep(Sys.Date(),5),z=c(3,2,5,23,6),w=c("a","a","b","b","c"))
p <- plot_ly(x= data[["x"]], y =data[["y"]] , z = data[["z"]], color = data[["w"]],
type="scatter3d", mode="markers")
p
#date not constant variable
data<-data.frame(x=c(1,2,3,4,5),y=c(rep(Sys.Date(),4),Sys.Date()+1),z=c(3,2,5,23,6),w=c("a","a","b","b","c"))
p <- plot_ly(x= data[["x"]], y =data[["y"]] , z = data[["z"]], color = data[["w"]],
type="scatter3d", mode="markers")
p
#factor constant variable
data<-data.frame(x=c(1,2,3,4,5),y=rep("A",5),z=c(3,2,5,23,6),w=c("a","a","b","b","c"))
p <- plot_ly(x= data[["x"]], y =data[["y"]] , z = data[["z"]], color = data[["w"]],
type="scatter3d", mode="markers")
p
#numeric constant variable
data<-data.frame(x=c(1,2,3,4,5),y=rep(1,5),z=c(3,2,5,23,6),w=c("a","a","b","b","c"))
p <- plot_ly(x= data[["x"]], y =data[["y"]] , z = data[["z"]], color = data[["w"]],
type="scatter3d", mode="markers")
p
Is there a way to solve this
Thanks for your help
Upvotes: 1
Views: 118
Reputation: 1037
Seems maybe like a bug from plotly side but basically the problem is that plotly cannot display large numeric numbers. It applies to 1589392544 (=as.numeric(Sys.time())
), too. Just add some formatting before the plotting:
library(plotly)
data<-data.frame(x=c(1,2,3,4,5),
y=rep(format(Sys.time(), "%Y-%M-%D %H:%M:%S"),5),
z=c(3,2,5,23,6),
w=c("a","a","b","b","c"))
p <- plot_ly(data, x=~x, y =~y , z =~z, color = ~w,
type="scatter3d", mode="markers")
p
Upvotes: 1