Description Usage Arguments Details Examples
Generate an interactive 3D chart.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | graph3d(
data = NULL,
x = ~x,
y = ~y,
z = ~z,
frame = NULL,
style = NULL,
type = "surface",
surfaceColors = c("#FF0000", "#FFF000", "#00FF00", "#68E8FB", "#000FFF"),
dataColor = NULL,
xBarWidth = NULL,
yBarWidth = NULL,
xlab = NULL,
ylab = NULL,
zlab = NULL,
xValueLabel = NULL,
yValueLabel = NULL,
zValueLabel = NULL,
width = "100%",
height = "100%",
backgroundColor = NULL,
showPerspective = TRUE,
showGrid = TRUE,
showShadow = FALSE,
showXAxis = TRUE,
showYAxis = TRUE,
showZAxis = TRUE,
axisColor = NULL,
axisFontSize = 30,
gridColor = NULL,
keepAspectRatio = TRUE,
verticalRatio = 0.5,
tooltip = TRUE,
tooltipDelay = NULL,
tooltipStyle = NULL,
showLegend = TRUE,
legendLabel = NULL,
cameraPosition = list(horizontal = 1, vertical = 0.5, distance = 2.8),
xCenter = NULL,
yCenter = NULL,
xMin = NULL,
xMax = NULL,
yMin = NULL,
yMax = NULL,
zMin = NULL,
zMax = NULL,
xStep = NULL,
yStep = NULL,
zStep = NULL,
showAnimationControls = TRUE,
animationInterval = 100,
animationPreload = TRUE,
frameLabel = NULL,
onclick = NULL,
elementId = NULL
)
|
data |
dataframe containing the data for the chart; if not |
x |
a right-sided formula giving the variable for the locations of the points on the x-axis; required |
y |
a right-sided formula giving the variable for the locations of the points on the y-axis; required |
z |
a right-sided formula giving the variable for the locations of the points on the z-axis; required |
frame |
a right-sided formula giving the variable for the frames of the animation; optional |
style |
a right-sided formula required for |
type |
the type of the chart, one of |
surfaceColors |
a vector of colors for |
dataColor |
a string or a list; see the |
xBarWidth, yBarWidth |
the widths of bars in x and y directions for
|
xlab |
string, the label on the x-axis |
ylab |
string, the label on the y-axis |
zlab |
string, the label on the z-axis |
xValueLabel |
JavaScript function for custom formatting of the labels
along the x-axis, for example |
yValueLabel |
same as |
zValueLabel |
same as |
width, height |
the dimensions of the chart given as strings, in pixels
(e.g. |
backgroundColor |
the background color of the chart, either a string
giving a HTML color (like |
showPerspective |
logical; if |
showGrid |
logical; if |
showShadow |
logical, whether to show shadow on the graph |
showXAxis |
logical; if |
showYAxis |
logical; if |
showZAxis |
logical; if |
axisColor |
a HTML color given as a string, the color of the axis lines and the text along the axes |
axisFontSize |
a positive number, the font size of the axes labels |
gridColor |
a HTML color given as a string, the color of the grid lines |
keepAspectRatio |
logical; if |
verticalRatio |
value between 0.1 and 1 which scales the vertical
size of the graph; when |
tooltip |
logical, whether to see the tooltips, or a JavaScript function to customize the tooltips; see the barplot example |
tooltipDelay |
a number, the delay time in ms for the tooltip to appear when the mouse cursor hovers over an x-y grid tile |
tooltipStyle |
a list of tooltip style properties; see the vis-graph3d documentation |
showLegend |
logical, whether to see the legend if the graph type supports it |
legendLabel |
a string, the label of the legend |
cameraPosition |
a list with three fields to set the initial rotation
and position if the camera: |
xCenter |
a string giving the horizontal center position of the graph
as a percentage (like |
yCenter |
same as |
xMin |
minimum value for the x-axis; if not set, the smallest value of
|
xMax |
maximum value for the x-axis; if not set, the largest value of
|
yMin |
minimum value for the y-axis; if not set, the smallest value of
|
yMax |
maximum value for the y-axis; if not set, the largest value of
|
zMin |
minimum value for the z-axis; if not set, the smallest value of
|
zMax |
maximum value for the z-axis; if not set, the largest value of
|
xStep |
a number, the step size for the grid on the x-axis |
yStep |
a number, the step size for the grid on the y-axis |
zStep |
a number, the step size for the grid on the z-axis |
showAnimationControls |
logical, only applicable when the graph
contains an animation (i.e. |
animationInterval |
a number, the animation interval in milliseconds; default to 1000 |
animationPreload |
logical; if |
frameLabel |
string, the label for the animation slider |
onclick |
a JavaScript function to handle the click event on a point;
see the vis-graph3d documentation and the second example in
|
elementId |
an id for the widget |
See the vis-graph3d documentation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | # 3d bar plot ####
dat <- data.frame(x = c(1,1,2,2), y = c(1,2,1,2), z = c(1,2,3,4))
graph3d(dat, type = "bar", zMin = 0)
# change bar widths
graph3d(dat, type = "bar", zMin = 0, xBarWidth = 0.3, yBarWidth = 0.3)
# with custom tooltips
graph3d(dat, type = "bar", zMin = 0,
tooltip = JS(c("function(xyz){",
" var x = 'X: ' + xyz.x.toFixed(2);",
" var y = 'Y: ' + xyz.y.toFixed(2);",
" var z = 'Z: ' + xyz.z.toFixed(2);",
" return x + '<br/>' + y + '<br/>' + z;",
"}"))
)
# bivariate Gaussian density ####
dat <- expand.grid(
x = seq(-4,4,length.out=100),
y = seq(-4,4,length.out=100)
)
dat <- transform(dat, density = dnorm(x)*dnorm(y))
graph3d(dat, z = ~density, keepAspectRatio = FALSE, verticalRatio = 1)
# animation ####
f <- function(x, y) sin(x/50) * cos(y/50) * 50 + 50
t_ <- seq(0, 2*pi, length.out = 90)[-90]
x_ <- y_ <- seq(0, 314, length.out = 50)
dat <- expand.grid(x = x_, y = y_, t = t_)
dat <- transform(dat, z = f(x*cos(t) - y*sin(t), x*sin(t) + y*cos(t)))
graph3d(dat, frame = ~t, tooltip = FALSE)
# scatterplot ####
dat <- iris
dat$style <- I(lapply(iris$Species, function(x){
switch(as.character(x),
setosa = list(fill="red", stroke="#'000"),
versicolor = list(fill="green", stroke="#'000"),
virginica = list(fill="blue", stroke="#'000"))
}))
graph3d(dat, x = ~Sepal.Length, y = ~Sepal.Width, z = ~Petal.Length,
style = ~style, type = "dot-color", showLegend = FALSE)
# line ####
t_ <- seq(0, 2*pi, length.out = 200)
dat <- data.frame(
x = cos(t_),
y = sin(t_),
z = 2 * cos(3*t_)
)
graph3d(dat, type = "line", dataColor = list(strokeWidth = 5, stroke = "red"),
verticalRatio = 1)
# a complex function ####
dat <- expand.grid(
x = seq(-1, 1, length.out = 100),
y = seq(-1, 1, length.out = 100)
)
dat <- transform(dat, sine = sin(x + 1i*y))
dat <- transform(dat, modulus = Mod(sine), phase = Arg(sine))
graph3d(dat, z = ~modulus, style = ~phase, type = "dot-color",
legendLabel = "phase")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.