0

I'm trying to create a perspective graph in R and keep getting the increasing 'x' and 'y' error. I've tried numerous options but I can't seem to figure this out. Any help would be appreciated!

fit.A <- data.frame(Temp.f="Ambient",x,y)
fit.A$pred <- predict(model=lrNH4,newdata=fit.A)

x
 [1] 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
[17] 0.619 0.626 0.630 0.635 0.649 0.656 1.902 1.947 1.967 2.056 2.689 2.707 2.758 2.760 2.943 2.978
[33] 2.992 3.020 4.564 4.854 5.893 6.029 6.051 6.067

y
 [1] 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
[17] 0.479 0.530 0.566 0.605 0.635 0.726 1.909 1.916 2.128 2.195 2.636 2.645 2.747 2.777 2.943 3.057
[33] 3.169 3.203 4.657 4.813 5.956 5.986 6.154 6.157

persp(x,y,z=matrix(fit.A$pred,nrow=length(x),ncol=length(y),byrow=TRUE),
zlim=c(140,700))

Error in persp.default(x, y, z = matrix(fit.A$pred, nrow = length(x), : increasing 'x' and 'y' values expected

Psidom
  • 209,562
  • 33
  • 339
  • 356
eamoore
  • 11
  • 1
  • 3

1 Answers1

0

Your x and y values aren't increasing- they stay stuck at 0 for the first batch of rows.

To create a perspective plot, remove all rows where x and/or y are duplicated. This could be done with:

fit.A <- fit.A[!duplicated(fit.A$x), ]

(In different data it's possible you'd need to filter for duplicated y as well).

David Robinson
  • 77,383
  • 16
  • 167
  • 187