3D Isosurface Plots in R
How to create 3D isosurface plots with Plotly.
Plotly Studio: Transform any dataset into an interactive data application in minutes with AI. Sign up for early access now.
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
Isosurface with Additional Slices
library(plotly)
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/clebsch-cubic.csv')
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)
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/clebsch-cubic.csv')
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
Reference
See our reference page for more information and chart attribute options!.
What About Dash?
Dash for R is an open-source framework for building analytical applications, with no Javascript required, and it is tightly integrated with the Plotly graphing library.
Learn about how to install Dash for R at https://dashr.plot.ly/installation.
Everywhere in this page that you see fig
, you can display the same figure in a Dash for R application by passing it to the figure
argument of the Graph
component from the built-in dashCoreComponents
package like this:
library(plotly)
fig <- plot_ly()
# fig <- fig %>% add_trace( ... )
# fig <- fig %>% layout( ... )
library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)
app <- Dash$new()
app$layout(
htmlDiv(
list(
dccGraph(figure=fig)
)
)
)
app$run_server(debug=TRUE, dev_tools_hot_reload=FALSE)