How do I add leaf label margin in dendrogram?

19 Views Asked by At

I'm plotting a dendrogram, but leaf labels overlap the shape:

enter image description here

The code:

scanpy_dendrogram <- dendrapply(scanpy_dendrogram, function(current_node) {
  if(is.leaf(current_node)){
    leaf_attrs <- attributes(current_node)
        
    current_idx <- match(leaf_attrs$label, scanpy_lfc_data$comparison)
    current_cell_type <- scanpy_lfc_data[current_idx, 2]
    current_dataset <- scanpy_lfc_data[current_idx, 3]
    dataset_color <- dataset_colors[[current_dataset]]
    attr(current_node, 'label') <- current_cell_type
    attr(current_node, 'nodePar') <- c(
      leaf_attrs$nodePar,
      list(
        cex = 2,
        lab.cex = 0.6,
        pch = 20,
        col = dataset_color,
        lab.font = 1,
        mar=c(0, 0, 10, 0)
      )
    )
  }
  return(current_node)
})
plot(scanpy_dendrogram)

Where scanpy_dendrogram is:

'dendrogram' with 2 branches and 117 members total, at height 62.44164 

As you can see, I tried adding mar to the node params, but that's probably a wrong place to add margin.

0

There are 0 best solutions below