Show Sidebar Hide Sidebar

# 3D Mesh Plots in R

How to make interactive 3D mesh plots in R.

### New to Plotly?

Plotly's R library is free and open source!
You can set up Plotly to work in online or offline mode.
We also have a quick-reference cheatsheet (new!) to help you get started!

### Version Check

Version 4 of Plotly's R package is now available!
Check out this post for more information on breaking changes and new features available in this version.

``````library(plotly)
packageVersion('plotly')
``````
``````## [1] '4.5.5.9000'
``````

### Basic 3D Mesh Plot

``````library(plotly)

x <- runif(50, 0, 1)
y <- runif(50, 0, 1)
z <- runif(50, 0, 1)

p <- plot_ly(x = ~x, y = ~y, z = ~z, type = 'mesh3d')

# Set up API credentials: https://plot.ly/r/getting-started
``````

### Tetrahedron Mesh Plot

``````library(plotly)

p <- plot_ly(type = 'mesh3d',
x = c(0, 1, 2, 0),
y = c(0, 0, 1, 2),
z = c(0, 2, 0, 1),
i = c(0, 0, 0, 1),
j = c(1, 2, 3, 2),
k = c(2, 3, 1, 3),
intensity = c(0, 0.33, 0.66, 1),
color = c(0, 0.33, 0.66, 1),
colors = colorRamp(c("red", "green", "blue"))
)

# Set up API credentials: https://plot.ly/r/getting-started
``````

### Cube Mesh Plot

``````library(plotly)

p <- plot_ly(type = 'mesh3d',
x = c(0, 0, 1, 1, 0, 0, 1, 1),
y = c(0, 1, 1, 0, 0, 1, 1, 0),
z = c(0, 0, 0, 0, 1, 1, 1, 1),
i = c(7, 0, 0, 0, 4, 4, 6, 6, 4, 0, 3, 2),
j = c(3, 4, 1, 2, 5, 6, 5, 2, 0, 1, 6, 3),
k = c(0, 7, 2, 3, 6, 7, 1, 1, 5, 5, 7, 6),
intensity = seq(0, 1, length = 8),
color = seq(0, 1, length = 8),
colors = colorRamp(rainbow(8))
)