# Generate a random tree
tree <- ape::rcoal(20)
# Create a presence-absence matrix
mat <- matrix(sample(c(1,0), 20*10, replace = TRUE), ncol = 20, nrow = 10)
colnames(mat) <- tree$tip.label
# Calculate the CpD for 100 tree slices
CpD_DF <- CpD(tree, n = 100, mat = mat)
# Plot it using the CpR_graph
CpR_graph(CpD_DF, rate = "CpD")
Run the code above in your browser using DataLab