3D Plot in R

2019-08-19 Rahul Swami Download Code

In R programming there are various function for creating 3D plots. we discuss the persp( ) function for creating the 3D surfaces.

There are three variables, x , y and z where x and y are the vectors that define the location of x-axis and y-axis. The height of surface will be definig z-axis.

 

cone <- function(x, y)   #cone obtained the function
{
   sqrt(x^2+y^2)
}

x <- y <- seq(-1, 1, length= 20)  #variables
z <- outer(x, y, cone)

persp(x, y, z)

seq()  -  to generate vector of equally spaced numbers.

outer() - to apply the function cone at every combination of x and y.

 


About author

Card image cap
Rahul Swami

Experienced in providing key insights with advanced statistical methods, data modeling, and graphical display, utilizing the software that best suits your needs, with advanced skill in R.!

-R Developer

0 Comments