# NOT RUN {
set.seed(1)
g <- sample_islands(3, 10, 5/10, 1)
i <- cluster_louvain(g)
(graphjs(g, vertex.color=c("orange", "green", "blue")[i$membership], vertex.shape="sphere"))
# similar example with user-defined directional lighting
l1 = light_directional(color = "red", position = c(0, -0.8, 0.5))
l2 = light_directional(color = "yellow", position = c(0, 0.8, -0.5))
l3 = light_ambient(color = "#555555")
(graphjs(g, vertex.color="gray", vertex.shape="sphere", lights=list(l1, l2, l3)))
# Les Miserables Character Co-appearance Data
data("LeMis")
(graphjs(LeMis))
# ...plot Character names
(graphjs(LeMis, vertex.shape=V(LeMis)$label))
# SNAP Facebook ego network dataset
data("ego")
(graphjs(ego, bg="black"))
# }
# NOT RUN {
# A shiny example
shiny::runApp(system.file("examples/graph", package="threejs"))
# A graph amination that shows several layouts
data("LeMis")
graphjs(LeMis,
layout=list(
layout_randomly(LeMis, dim=3),
layout_on_sphere(LeMis),
layout_with_drl(LeMis, dim=3), # note! somewhat slow...
layout_with_fr(LeMis, dim=3, niter=30)),
main=list("random layout", "sphere layout", "drl layout", "fr layout"),
fpl=300)
# A simple graph animation illustrating edge modification
g <- make_ring(5) - edges(1:5)
graph_list <- list(
g + edge(1, 2),
g + edge(1, 2) + edge(2, 3),
g + edge(1, 2) + edge(2, 3) + edge(3, 4),
g + edge(1, 2) + edge(2, 3) + edge(3, 4) + edge(4, 5),
g + edge(1, 2) + edge(2, 3) + edge(3, 4) + edge(4, 5) + edge(5, 1))
graphjs(graph_list, main=paste(1:5),
vertex.color=rainbow(5), vertex.shape="sphere", edge.width=3)
# see `demo(package="threejs") for more animation demos.
# A crosstalk example
library(crosstalk)
library(DT)
data(LeMis)
sd = SharedData$new(data.frame(Name = V(LeMis)$label))
print(bscols(
graphjs(LeMis, brush=TRUE, crosstalk=sd),
datatable(sd, rownames=FALSE, options=list(dom='tp'))
))
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab