sphere3js | R Documentation |
Unlike points3js, where geometric points can also be represented as spheres, this adds sphere that is sized with respect to the actual dimensions of the plotting space (and so if aspect ratios differ for each axis may not actually appear sphere-like).
sphere3js(data3js, x, y, z, radius, col = "black", highlight, ...)
data3js |
The data3js object |
x |
x coordinate of the sphere center |
y |
y coordinate of the sphere center |
z |
z coordinate of the sphere center |
radius |
sphere radius |
col |
color |
highlight |
highlight attributes (see |
... |
other arguments to pass to |
Returns an updated data3js object
Other plot components:
arrows3js()
,
axis3js()
,
box3js()
,
grid3js()
,
legend3js()
,
light3js()
,
lines3js()
,
mtext3js()
,
points3js()
,
segments3js()
,
shape3js()
,
surface3js()
,
text3js()
,
triangle3js()
# Setup base plot
p <- plot3js(
xlim = c(-10, 10),
ylim = c(-5, 5),
zlim = c(-8, 8)
)
# Add sphere (this will look distorted because of axis scaling)
p <- sphere3js(
data3js = p,
0, 0, 0,
radius = 5,
col = "green"
)
r3js(p, zoom = 2.5)
# Setup base plot with equal aspect ratio
p <- plot3js(
xlim = c(-10, 10),
ylim = c(-5, 5),
zlim = c(-8, 8),
aspect = c(1, 1, 1)
)
# Add sphere (fixed aspect ratio now makes the sphere look spherical)
p <- sphere3js(
data3js = p,
0, 0, 0,
radius = 5,
col = "green"
)
r3js(p, zoom = 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.