Ryan
Ryan

Reputation: 1068

How to make 3-D time series plots

I have time series data on 10 individuals, similar to what is created below. I am looking for a way to make a 3-D plot similar to this example: enter image description here

Except I want each unique ID to be where year is in the picture

set.seed(123)
ID <- rep(1:10, each = 500)
Time = rep(c(1:500),10)
Var <- rnorm(5000)
data <- data.frame(
  ID = factor(ID),
  Time = Time,
  Variable = Var
)

Upvotes: 1

Views: 1305

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226871

As a very quick, and ugly start, try

library(plot3D)
## rearrange data into matrix form
m <- matrix(
  data$Variable,
  nrow=length(unique(data$ID)))
hist3D(z = m)

This doesn't look at all like your example plot; on the other hand, your data don't look much like the data in this plot. Things I haven't played around with yet:

  • axis labels
  • making sure the matrix is actually oriented in the right way (this will be a lot easier with real data!)
  • changing aspect ratio

Upvotes: 2

Related Questions