Skip to contents

This function first obtains an SVG representation of the tree by calling the draw_svg method of tskit and renders it as a bitmap image in R. All of the many optional keyword arguments of the draw_svg method can be provided and will be automatically passed to the method behind the scenes.


  width = 1500,
  height = 500,
  labels = FALSE,
  sampled_only = TRUE,



A single tree extracted by ts_tree

width, height

Pixel dimensions of the rendered bitmap


Label each node with the individual name?


Should only individuals explicitly sampled through simplification be labeled? This is relevant in situations in which sampled individuals can themselves be among the ancestral nodes.


Keyword arguments to the tskit draw_svg function.


No return value, called for side effects


check_dependencies(python = TRUE) # make sure dependencies are present

#> The interface to all required Python modules has been activated.

# load an example model with an already simulated tree sequence
slendr_ts <- system.file("extdata/models/introgression.trees", package = "slendr")
model <- read_model(path = system.file("extdata/models/introgression", package = "slendr"))

# load the tree-sequence object from disk
ts <- ts_load(slendr_ts, model, simplify = TRUE)

# extract the first tree in the tree sequence and draw it
tree <- ts_tree(ts, i = 1)

# ts_draw accepts various optional arguments of tskit.Tree.draw_svg
ts_draw(tree, time_scale = "rank")
#> Error in ts_draw(tree, time_scale = "rank"): For plotting trees using the native SVG tskit capabilities, please
#> install the R package rsvg by calling `install.packages("rsvg")