0

I am doing some hierarchical cluster analyses of some ecological data & I am struggling w/the labels, which are numeric and all but meaningless: dendogram w/meaningless labels

Essentially I would like to bind together the two factorial columns in my data to create labels that clarify which data points are what, and I do not understand R's labelling system well enough to understand what I am trying to do.

If seeing my code will help you understand better, then here it is:

nta ##data frame: 32obs, 40 variables - 
    ##$Quadrant factor w/8levels
    ##$Position factor w/4levels
nta.bc ##bray-curtis dissimilarity matrix of data
nta.hclust ##average-linked cluster object of nta.bc

##attempt to plot w/labels
plot(nta.hclust) +
  labels(nta, which = c(nta$Quadrant,nta$Position)) +
  rect.hclust(nta.hclust,k=4)

does anyone have any pointers?

  • What distance/similarity matrix you're using to build the hclust? If your matrix has the labels then your plots should also have them. – Shibaprasadb Sep 14 '22 at 10:20
  • Bray-Curtis through the vegan package function vegdist I could add the columns to the dist matrix but as I would like to aggregate the labels from the values of the two factors would that work? – Dean Bayliss Sep 14 '22 at 10:34

1 Answers1

0

You should include sample data using dput() so that we can illustrate the answer with a sample of your own data. Also provide actual code not comments since the problem may lie in your code. Here is an example using the varespec data that is included in package vegan. The main problem is that you are using ggplot2 syntax with base graphics functions. Did you get error messages that you did not include in your question?

data(varespec)    # Load varspec data set included in vegan
vsp.bc <- vegdist(varespec, method="bray")
vsp.hcl <- hclust(vsp.bc, method="average")
plot(vsp.hcl, labels=paste("Plot", rownames(varespec)))
rect.hclust(vsp.hcl, k=4)

Dendrogram

dcarlson
  • 10,936
  • 2
  • 15
  • 18
  • That's worked for me! plot(nta.hclust, label=paste(nta$Quadrant,nta$Position)) + rect.hclust(nta.hclust,k=4) this code does return an error: non-numeric argument to binary operator which I imagine comes from using the '+' to run both lines of code sequentially, however, I can't see how this would affect the results of my dendogram – Dean Bayliss Sep 14 '22 at 16:22
  • It is your `labels( . . . )` line. There is a `labels()` function in R, but it returns labels from an object so it does not have a `which=` argument. The `labels=` argument in the `plot(..)` function sets the labels for the dendrogram. – dcarlson Sep 14 '22 at 17:02