树状图:按特征分组

Dendrogram: Grouping By Characteristics

我过去曾根据各种在线教程(例如 https://rstudio-pubs-static.s3.amazonaws.com/33876_1d7794d9a86647ca90c4f182df93f0e8.html)制作树状图

目标:Category 分组 Exposures,并在 tree/dendrogram 中可视化(例如 ExpAExpD 将被组合在一起,因为它们都是 HeavyMetals)

背景: 我正在尝试 tree/dendrogram 以下内容:

Exposures = c("ExpA","ExpB", "ExpC","ExpD","ExpE", "ExpF")
Category = c("HeavyMetal","Hormone", "Pesticide", "HeavyMetal", "Pesticide", "Hormone" )
dataframe = data.frame(Exposures,Category)

我试过以下方法:

hp = hclust(dist(dataframe))
plot(hp, labels = Exposures)

但我收到一条错误消息:

Error in hclust(dist(dataframe1)) : 
  NA/NaN/Inf in foreign function call (arg 11)
In addition: Warning message:
In dist(dataframe1) : NAs introduced by coercion

我认为错误信息是因为我没有任何数值数据但我不确定。

问题: 考虑到上述目标,是否有一种方法可以从类似于上述数据帧的数据帧创建 tree/dendrogram 结构?

谢谢!

install.packages('cluster')
library('cluster')
dissimilarity <- daisy(dataframe)
hc = hclust(dissimilarity)
plot(hc, labels = Exposures)