Reputation: 833
I am trying to come up with a way of displaying my data, which looks like this.
Day Signal Week
1 -0.01 1
2 0.03 1
3 0.01 1
4 -0.001 1
5 0.09 1
1 -0.10 2
2 -0.012 2
3 0.05 2
4 0.07 2
5 -0.01 2
The data represents return data from Monday to Friday for a given week. What I want to show in the most fancy way is how stable the signal behaves over time. The axis have to be like this plot that I created
So I want to have my x-axis to represent the days, the y-axis the signal and the z axis the weeks. So each week should be visible as a slice. Ideally I would have sth like this Image. I tried inputting the data as a matrix into plot_ly which didn't work. I am fairly new to R so any help would be appreciated
[EDIT] That's what I tried so far where mat is the data from above in one matrix with 3 columns
scatterplot3d(mat$x,mat$y,mat$z,main="lovely graph")
plot_ly(mat, type = "surface")
Upvotes: 1
Views: 104
Reputation: 5249
Try this. It assumes that you're original data is a data.frame called df
.
library(plotly)
library(reshape2)
df1 <- dcast(df,Day~Week,value.var="Signal")
mat <- as.matrix(df1[,-1])
plot_ly(z=mat, type="surface")
If you want to change the axis labels you can do the following:
plot_ly(z=mat, type="surface") %>%
layout(scene = list(xaxis = list(title = "Week"),
yaxis = list(title = "Day")))
Upvotes: 1