Black Lives Matter. Please consider donating to Black Girls Code today.

# 3D Isosurface Plots in R

How to create 3D isosurface plots with Plotly.

New to Plotly?

Plotly is a free and open-source graphing library for R. We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials.

#### Basic Isosurface Plot

``````library(plotly)

fig <- plot_ly(
type='isosurface',
x = c(0,0,0,0,1,1,1,1),
y = c(1,0,1,0,1,0,1,0),
z = c(1,1,0,0,1,1,0,0),
value = c(1,2,3,4,5,6,7,8),
isomin=2,
isomax=6
)

fig
``````

``````library(plotly)

fig <- plot_ly(
df,
type='isosurface',
x = ~x,
y = ~y,
z = ~z,
value = ~value,
isomin = -100,
isomax = 100,
colorscale='RdBu',
surface = list(show = TRUE, count = 1),
slices = list(z = list(
show = TRUE, locations = c(-0.3, 0.5)
)),
caps = list(
x = list(show = FALSE),
y = list(show = FALSE),
z = list(show = FALSE)
)
)
fig <- fig %>%
layout(
margin=list(t = 0, l = 0, b = 0),
scene=list(
camera=list(
eye=list(
x = 1.86,
y = 0.61,
z = 0.98
)
)
)
)

fig
``````

#### Multiple Isosurfaces with Caps

``````library(plotly)

fig <- plot_ly(
df,
type='isosurface',
x = ~x,
y = ~y,
z = ~z,
value = ~value,
isomin = -10,
isomax = 10,
surface = list(show = TRUE, count = 4, fill = 0.8, pattern = 'odd'),
caps = list(
x = list(show = TRUE),
y = list(show = TRUE),
z = list(show = TRUE)
)
)
fig <- fig %>%
layout(
margin=list(t = 0, l = 0, b = 0),
scene=list(
camera=list(
eye=list(
x = 1.86,
y = 0.61,
z = 0.98
)
)
)
)

fig
``````