2

I have a large data set which I would like to make a 3D surface from. I would like the x-axis to be the date, the y-axis to be the time (24h) and the z-axis (height) to be a value I have ($). I am a beginner with R, so the simpler the better!

http://www.quantmod.com/examples/chartSeries3d/ has a nice example, but the code is way to complicated for my skill level!

Any help would be much appreciated - anything I have researched so far needs to have the data sorted, which is not suitable I think.

4

1 に答える 1

7

いくつかのオプションがpersp()ありwireframe()、後者はパッケージのlatticeにあります。

最初のダミーデータ:

set.seed(3)
dat <- data.frame(Dates = rep(seq(Sys.Date(), Sys.Date() + 9, by = 1), 
                              each = 24),
                  Times = rep(0:23, times = 10),
                  Value = rep(c(0:12,11:1), times = 10) + rnorm(240))

persp()xおよびグリッド位置としてのデータと、観測値yの行列が必要です。z

new.dates <- with(dat, sort(unique(Dates)))
new.times <- with(dat, sort(unique(Times)))
new.values <- with(dat, matrix(Value, nrow = 10, ncol = 24, byrow = TRUE))

次を使用してプロットできます。

persp(new.dates, new.times, new.values, ticktype = "detailed", r = 10, 
      theta = 35, scale = FALSE)

ファセットは、col引数を使用して色付けできます。chartSeries3d0()リンク先のページのコードを勉強するよりも、はるかに悪いことをする可能性があります。コードのほとんどは、オブジェクトを簡単に処理しpersp()たりwireframe()処理したりしないため、適切な軸を描画するだけです。Date

についてはwireframe()

require(lattice)
wireframe(Value ~ as.numeric(Dates) + Times, data = dat, drape = TRUE)

現時点ではwireframe()、クラスのオブジェクトでは機能しないため、軸のラベル付けを整理するために少し作業するか作業する必要があります(したがって、数値としてキャストされます)。"Date"

于 2011-06-22T08:28:48.973 に答える