Just add the Plotly library into your RStudio environment then add a Plotly username and key:

1

2

3

4

install.packages("plotly")

library(plotly)

py<-plotly()

set_credentials_file(username='your_username',key='your_key')

To create a surface plot, use two vectors: x and y of length m and n, and a matrix: z of size m*n. In this example, x and y both consist of 100 points ranging from -5 to 4.9.

1

x_vec=c(seq(-5,4.9,0.1))

*note this results in the same dimensions (1 column X 100 rows) as specifying:

1

x_matrix=matrix(c(x_vec),nrow=100,ncol=1)

The size of x is 1 column with 100 rows. In order to multiply x * y to create matrix z with 100 columns and 100 rows, y should be 100 columns with 1 row.

1

y_matrix=matrix(c(x_vec),nrow=1,ncol=100)

To multiply the vertical and horizontal vectors to create matrix z in RStudio, the basic syntax is z = x %*% y. In this example, a function is applied to z to create waves. Below, dimensions x, y, and z are defined. y used here is different than y1 used above because y should be the default, 1 column vector, not 1 row x 100 columns. Type is defined as “surface”.