0

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)
Alex
  • 19,533
  • 37
  • 126
  • 195

1 Answers1

1

1 - Your understanding is correct.

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

Community
  • 1
  • 1
krokodil
  • 1,326
  • 10
  • 18