Alex
Alex

Reputation: 19833

perspective plot in R (tick marks and understanding what is going on)

I plot a 3d plot in R using persp. I have two questions with respect to this:

  1. Want to verify that I understand the docs correctly. persp will take the valuex from x and y, then depending on the index of each value in those vectors, say (i,j) corresponding to the current element in x and y, (x[i],y[j]), it will pluck out zfit[i,j] and plot (x[i],y[j],zfit[i,j]). Is this correct?

  2. This does not produce the numbers on the actual axis but arrows in the increasing direction. How do I make numbers appear?

Example:

set.seed(1)
x = 1:10
y = rnorm(10)
z = x + y^2
g = expand.grid(list(x=seq(from=min(x), to=max(x), length.out=100),y=seq(from=min(y), to=max(y), length.out=100)))
mdl = loess(z ~ x+ y)
zfit = predict(mdl, newdata=g)
persp(x = seq(from=min(x), to=max(x), length.out=100), y = seq(from=min(y), to=max(y), length.out=100), z= zfit)

Upvotes: 0

Views: 573

Answers (1)

krokodil
krokodil

Reputation: 1366

1 - Your understanding is correct.

2 - Add ticktype = "detailed" to show numbers on axis.

Upvotes: 1

Related Questions