3

I am conducting a regression tree using state sequence analysis and I want the image output to have the dimensions of a Letter size paper (landscape).

When I use the code I include the regression tree appears as a separate window, always of the same size, and the actual file in my computer is empty. I have to "Save as" the window that pops in order to get the regression tree, but the size is even (width, height). I would appreciate any help:

st_tk <- seqtree(tk.seq ~  Gender + age_groups + race_eth + Paying_rec + Marital + 
                           Education_rec + Pop + Employment_rec + Housing + Criminal + 
                           alcohol + cocaine + cannabis + meth + benzo + diff_opioid + 
                           opioid_route + sum_comor + site,
                 data = df_seq_tree, 
                 R = 5000, 
                 diss = dist.dhd,
                 weight.permutation = "diss",
                 max.depth = 10,
                 pval = 0.05)

# Save the regression tree as a PNG image
png("Output/Takehome/Reg_tree/st_tk.png", width = 11, height = 8.5)
seqtreedisplay(st_tk, type = "d", border = NA, image.format = "png", gvpath = 'C:/Program Files/Graphviz',
               cex.main = 2)
dev.off()

Thanks in advance!

1 Answer 1

1

Unfortunately, I am not aware of any simple way to do it. The function seqtreedisplay uses graphviz and not the R graphic engine to produce the image. Therefore, calling png() does not have any effect.

in order to have more control, you need to call dot (the graphviz program) by yourself. This will allow you to change everything in the plot.

To do so, you can use the function seqtree2dot, which will generate the dot file as well as all required image.

seqtree2dot(st_tk, filename="mytree", type = "d", border = NA, cex.main = 2)

You can then modify the dot file to suit your needs. Finally, you can generate the image using graphviz/dot.

1
  • 1
    Thanks Matthias!! (Big fan of your work!). I managed to get every node by itself and I guess I'll arrange the regression tree myself to fit my document as the .dot file was a bit cryptic. Please keep on developing more SSA!!
    – idborquez
    Commented Jun 22, 2023 at 0:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.