代码:
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")
作为参考,这是我的数据格式化方式:
Variable 1 Variable 2 Variable 3
State 1 123 123 123
State 2 123 123 123
State 3 123 123 123
请注意,我已将行名称设置为状态而非数字。这是情节抓住标签的地方。
答案 0 :(得分:2)
设置mar
参数可以解决问题
以下是带有剪切标签的树形图的示例:
hc <- hclust(dist(USArrests), "ave")
hc <- as.dendrogram(hc)
par(mar=c(3,4,1,1))
plot(hc, horiz=TRUE)
这里带有完整标签的图片:
par(mar=c(3,4,1,6))
plot(hc, horiz=TRUE)