I'm producing dendrograms to compare song similarity of a bird species between states. However, I can't figure out how to prevent the state names from clipping when I produce the plot (click for example). Any ideas?
Code:
var.towhee <- read.csv(file="states.csv", header=TRUE, fill=TRUE)
rownames(var.towhee) <-var.towhee$State # Set row names to state name
var.towhee <- var.towhee[,-1] # Remove state column
library(vegan)
library(permute)
library(lattice)
norm <- decostand(var.towhee, method="normalize") # Normalize data
dis <- vegdist(norm, method="euclidian") # Calculate distances
UPGMA <- hclust(dis, method="average") # Cluster using UPGMA method
UPGMA <- as.dendrogram(UPGMA) # Convert hclust objects into dendrogram objects
plot(UPGMA, horiz=TRUE, xlab="Song Distance")
For reference this is how my data is formatted:
Variable 1 Variable 2 Variable 3
State 1 123 123 123
State 2 123 123 123
State 3 123 123 123
Note that I've set the row names to be states rather than numbers. This is where the plot is grabbing the labels from.
The problem can be solved setting mar
parameters.
Here is an example of a dendrogram with clipped labels:
hc <- hclust(dist(USArrests), "ave")
hc <- as.dendrogram(hc)
par(mar=c(3,4,1,1))
plot(hc, horiz=TRUE)
and here the figure with the complete labels:
par(mar=c(3,4,1,6))
plot(hc, horiz=TRUE)