Sizing node labels to fit - large family tree

I have been working on a family tree application (~ 5,000 nodes). I am working on a Mac (M2) in RStudio. I am using the RStudio to save the graph to a pdf file. Here’s the problem - long names run outside of the node box. I have fizedsize set to FALSE.

Any help appreciated. More than willing to provide additional information - I just don’t know how muc hto share.

Thanks,
STerling

Please share a cut-down graph with a few examples of offending nodes that display “too long”

Find attached a pdf file. The three nodes at the bottom all exceed the box width in the pdf.

Rplot03.pdf (164.3 KB)

What we need is a (smaller) input file (the graph definition).

Hmmm. The input file was. GED file I processed. Here’s the code related to actually plotting
Currently font size is set to 30. The pdf is currently set to 30" x 20". I’ve struggled to related the node width and height data (which I believe is in inches), with the font size (measured in pts). I’ve made the font smaller than 30, but then the text in the pdf disappears.

I’m not sure how pdfs work. It would appear the text is somehow scaled when fitting the graph to the page. If so, then with the page ~ 100 nodes wide, that’s 1/3 inch per node or 24 pts. If 24 characters are fit across a node, then each character is rendered at 1 pt font. But I’m not sure if that’s how things work.

setMethod(“plot”
,signature(gt=“GenTree”
#,format=“list”
)
,function(gt) { #},format) {

          # get the node data frame, with columns 
          #     id: id of node
          #     label: label to be displayed (includes line breaks)
          #     colour: colour of node (gender based)
          #     shape:  shape of node
          #     fontSize: font size to be used for node (30)
          nodes <- gt@nodes
          
          # get the edge data frame, with columns
          #     from: the node at which edge starts
          #     to:   the node at which the edge ends
          #     colour: the colour of the edge (grey)
          #     width: the width of the edge (0.1)
          edges <- gt@edges

          g <- graphNEL(nodes=nodes$id,edgemode="directed")

          g <- addEdges(g,gt@edges)
          g1 <- layoutGraph(g)

          nodeColour <- nodes$colour
          names(nodeColour) <- nodes$id
          nodeRenderInfo(g1) <- list(fill=nodeColour)
          
          nodeLineColour <- nodes$colour
          names(nodeLineColour) <- nodes$id
          nodeRenderInfo(g1) <- list(col=nodeLineColour)
          
          nodeShape <- nodes$shape
          names(nodeShape) <- nodes$id
          nodeRenderInfo(g1) <- list(shape=nodeShape)
          
          labels <- nodes$label
          names(labels) <- nodes$id
          
          nodeFontSize <- nodes$fontSize
          # graph.par sets parameters for all items. In this case, set
          # the font size for all nodes
          graph.par(list(nodes=list(fontsize=nodes$fontSize)))
          names(nodeFontSize) <- nodes$id
          
          nodeRenderInfo(g1) <- list(label=labels)
          
          fixedSize <- rep(FALSE,length(nodeLineColour))
          names(fixedSize) <- nodes$id
          nodeRenderInfo(g1) <- list(fixedsize=fixedSize)
         
          edgeColour <- gt@edges$colour
          # need to sort the edge information in the same order as edge names
          eNames <- paste0(gt@edges$from,"~",gt@edges$to)
          edgeColour <- edgeColour[match(edgeNames(g1),eNames)]
          names(edgeColour) <- edgeNames(g1)
          edgeRenderInfo(g1) <- list(col=edgeColour)
            
          
          graphRenderInfo(g1,c(nodesep=.5,width=60))
          renderGraph(g1)
          gt@graph <- g1
          
        return(gt)
          

}#function(gt,format)

)

I can’t debug RStudio or R (I assume RStudio uses R, but maybe not).
If you can create an output file of type dot instead of pdf, I will try to help.
Otherwise, try asking the RStudio folks.

Ok. I will look into generating a dot file for you

Hi Steve,

Find attached the dot file. I had created a graphNEL object, so had to convert it using agopenSimple, and then used toFile to create the dot file.
fred.dot (101.3 KB)

It’s not a problem with Graphviz or with your graph. It’s apparently a mismatch between the fonts Graphviz found and loaded when it computed the layout, and the fonts used in the final renderer in RStudio. It’s similar to a problem people sometimes have with graphviz SVG output, where you can’t be certain how a given font specification will be resolved at render time on different machines or even by different programs on the same machine. For now, probably the easiest thing is for you to just draw the graph using a shell command, e.g. dot -Gsize="10,10" -Tpdf fred.dot -o fred.pdf unless anyone has a better idea.

Many thanks. So … I’m guessing there’s a Mac executable for dot somewhere nearby. :slight_smile:

Ok. So I tried the suggested solution, and I now have a graph, with node width adjusted to fit the text. Nodes contain the id text, but node colour and labels are not presented. I had used ‘toFile’ to generate the dot file, so I would expect the dot file to have contained the needed information? Is there more to the command line that I simply need to learn about?

Thanks again for your patience

All the style, color, shape, … was lost in transit. If you look at fred.dot, you won’t find any of it.
Possibilities:

  • Find a way to get RStudio/R to provide all the stylish information
  • explicitly increase the width attribute of the “too small” nodes or all the nodes (I am skeptical)
  • insert more newlines (“\n”) into long names to make the text line shorter (then make the name text a different color to make it easier to read)
  • try different fonts (e.g. see Font FAQ | Graphviz) to see if you can find one that works OK

This is likely a RGraphviz problem, rather than Graphviz. The graph on the monitor is rendered properly, while the exported graph (to dot file) is not.

Thanks for all the help getting me this far.
Sterling