You can achieve this with standard R functions.
Plot a dendrogram
To plot a dendrogram from a distance matrix you can use the hclust
function. See its man page for further details on the algorithms available.
# To produce a dummy distance matrix
distMatrix <- dist(matrix(1:9, ncol=3))
# To convert it into a tree
tree <- hclust(distMatrix)
For the plot, the dendrogram
class provides a useful plot
method. Just convert the hclust output to dendrogram and plot it :
dendro <- as.dendrogram(tree)
This method provides a horiz
argument that can switch X and Y axis, test the following :
plot(dendro, horiz=TRUE)
plot(dendro, horiz=FALSE)
Manage its size
For the readability, it is up to the device you use for exporting the image. R can produce huge images, it is up to the user to set the size and resolution. See the man page for png
or pdf
for further details (width, height and res are interesting arguments).
An other track to follow is the graphical parameters : playing with the various cex
values, you will be able to resize the labels. See the man page of par
for further details.
Readability is quite human oriented, so i don't think you will find an automated way to obtain a readable plot automaticaly, but with a few manual tunning you can achieve it with the tools i mentionned. If automation is mandatory, it can be obtained using some par
elements generated by R like cin
to predict the needed device width, but it is much simpler to tune it manually.
New axis
The axis
function can help you.