# NOT RUN {
## Simple 3-simplex
st <- simplex_tree() %>% insert(list(1:4))
## Default is categorical colors w/ diminishing opacity
plot(st)
## If supplied colors have alpha defined, use that
vpal <- rainbow(st$dimension + 1)
plot(st, color_pal = vpal)
## If alpha not supplied, decreasing opacity applied
plot(st, color_pal = substring(vpal, first=1, last=7))
## Bigger example; observe only maximal faces (+vertices and edges) are drawn
st <- simplex_tree(list(1:3, 2:5, 5:9, 7:8, 10))
plot(st, color_pal = rainbow(st$dimension + 1))
## If maximal == FALSE, every simplex is drawn (even on top of each other)
vpal <- rainbow(st$dimension + 1)[c(1,2,5,4,3)]
pal_alpha <- c(1, 1, 0.2, 0.35, 0.35)
vpal <- sapply(seq_along(vpal), function(i) adjustcolor(vpal[i], alpha.f = pal_alpha[i]))
plot(st, color_pal = vpal, maximal = FALSE)
## You can also color each simplex individually by supplying a vector
## of the same length as the number of simplices.
plot(st, color_pal = sample(rainbow(sum(st$n_simplices))))
## The order is assumed to follow the level order traversal (first 0-simplices, 1-, etc.)
## This example colors simplices on a rainbow gradient based on the sum of their labels
si_sum <- straverse(st %>% level_order, sum)
rbw_pal <- rev(rainbow(50, start=0,end=4/6))
plot(st, color_pal=rbw_pal[cut(si_sum, breaks=50, labels = FALSE)])
## This also makes highlighting simplicial operations fairly trivial
four_cofaces <- as.list(cofaces(st, 4))
coface_pal <- straverse(level_order(st), function(simplex){
ifelse(list(simplex) %in% four_cofaces, "orange", "blue")
})
plot(st, color_pal=unlist(coface_pal))
## You can also give a named list to draw individual simplices.
## **Only the maximal simplices in the list are drawn**
blue_vertices <- structure(as.list(rep("blue", 5)), names=as.character(seq(5, 9)))
plot(st, color_pal=append(blue_vertices, list("5,6,7,8,9"="red")))
# }
Run the code above in your browser using DataLab