I have some data from mass spectrometry of some plant samples (11 morphospecies and 4 treatments for each). Each species/treatment yields a graphic like the one below.
Each column in the graphic indicates how much of that chemical substance is present in the sample. All the data was assembled in a single table, as shown below.
sp technique mz abundance sp1 ESIneg 118.89 3.01 sp1 ESIneg 172.72 3.20 sp1 ESIneg 202.94 3.80 sp1 ESIpos 118.30 2.59 sp1 ESIpos 170.68 3.13 sp1 ESIpos 257.97 3.28 sp2 ESIneg 132.33 22.22 sp2 ESIneg 211.84 3.87
The table has 1587 rows and 4 columns. Now, I would like to obtain a dendrogram like the following:
which was obtained from this simple example in R:
d <- dist(as.matrix(mtcars)) # find distance matrix hc <- hclust(d) # apply hirarchical clustering plot(hc) # plot the dendrogram
The problem is:
mtcars in this example is a table with no repeating rows. While in my case, there each species/treatment spans many rows (one for each column in the first graphic), I'm in a complete lost about how to proceed. In a related question, I've been told to use dummy variables through
model.matrix, but this still don't give me the sort of data I need.
How can i get a dendrogram showing the relatedness of all morphospecies, from my initial data?