# NOT RUN {
# Example 1 from the scatterplot3d package (cf.)
z <- seq(-10, 10, 0.1)
x <- cos(z)
y <- sin(z)
scatterplot3js(x, y, z, color=rainbow(length(z)))
# Same example with explicit axis labels
scatterplot3js(x, y, z, color=rainbow(length(z)), axisLabels=c("a", "b", "c"))
# Same example showing multiple point styles with pch
scatterplot3js(x, y, z, color=rainbow(length(z)),
pch=sample(c(".", "o", letters), length(x), replace=TRUE))
# Point cloud example, should run this with WebGL!
N <- 20000
theta <- runif (N) * 2 * pi
phi <- runif (N) * 2 * pi
R <- 1.5
r <- 1.0
x <- (R + r * cos(theta)) * cos(phi)
y <- (R + r * cos(theta)) * sin(phi)
z <- r * sin(theta)
d <- 6
h <- 6
t <- 2 * runif (N) - 1
w <- t^2 * sqrt(1 - t^2)
x1 <- d * cos(theta) * sin(phi) * w
y1 <- d * sin(theta) * sin(phi) * w
i <- order(phi)
j <- order(t)
col <- c( rainbow(length(phi))[order(i)],
rainbow(length(t), start=0, end=2/6)[order(j)])
M <- cbind(x=c(x, x1), y=c(y, y1), z=c(z, h*t))
scatterplot3js(M, size=0.5, color=col, bg="black", pch=".")
# Plot generic text using 'pch' (we label some points in this example)
set.seed(1)
x <- rnorm(5); y <- rnorm(5); z <- rnorm(5)
scatterplot3js(x, y, z, pch="@") %>%
points3d(x + 0.1, y + 0.1, z, color="red", pch=paste("point", 1:5))
# }
# NOT RUN {
# A shiny example
shiny::runApp(system.file("examples/scatterplot", package="threejs"))
# }
# NOT RUN {
# }
# NOT RUN {
# A crosstalk example
library(crosstalk)
library(d3scatter) # devtools::install_github("jcheng5/d3scatter")
z <- seq(-10, 10, 0.1)
x <- cos(z)
y <- sin(z)
sd <- SharedData$new(data.frame(x=x, y=y, z=z))
print(bscols(
scatterplot3js(x, y, z, color=rainbow(length(z)), brush=TRUE, crosstalk=sd),
d3scatter(sd, ~x, ~y, width="100%", height=300)
))
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab