1

This is what I'm doing

mat <-  read.table("Model_pvclust/Model18_FAB_M5_vs_M0_MAP_TF.txt",sep = "\t",strip.white = FALSE,check.names = FALSE,header=TRUE,row.names=1)
drop <- c("gene","baseMean","log2FoldChange","lfcSE","stat","pvalue","padj","UP_DOWN")

d1 <- select(mat, -one_of(drop))

####### Read the metadata

metadata <-read.table("Model_hmap_meta/FAB_table.txt",sep = "\t",strip.white = FALSE,check.names = FALSE,header=TRUE,row.names=1)
head(metadata)



head(metadata)
             prior_malignancy FAB    Risk_Cyto
TCGA-AB-2856               no  M4 Intermediate
TCGA-AB-2849               no  M0         Poor
TCGA-AB-2971               no  M4 Intermediate
TCGA-AB-2930               no  M2 Intermediate
TCGA-AB-2891               no  M1         Poor
TCGA-AB-2872               no  M3         Good

Plotting the cluster

pvc <- pvclust( data = d1 , method.dist = "correlation", method.hclust = "complete",parallel = T)
plot(pvc,las=2,hang = -0.5)
pvrect(pvc, alpha = 0.9)

Image that i get is where My sample names are labelled. Instead of those sample names I would like to label them based on that FAB columns matching the sample name order.

My data files mat and my metadata

pvclust figure

Updated answerupdated image

Tal Galili
  • 24,605
  • 44
  • 129
  • 187
PesKchan
  • 868
  • 6
  • 14

1 Answers1

2

You can replace the current labels using the dendextend::labels function.

library("dendextend")
labels(pvc$hclust) <- metadata$FAB
plot(pvc,las=2,hang = -0.5)
pvrect(pvc, alpha = 0.9)

enter image description here

Adam Quek
  • 6,973
  • 1
  • 17
  • 23
  • wow let me run... – PesKchan Jul 11 '22 at 12:28
  • Im getting numbers in my label not the FAB label ..I wil attach the image why is it so? I ran the code you have provided in the answer...updated the figure in my question have a look what is wrong here i would like to know – PesKchan Jul 11 '22 at 12:33
  • 1
    Not sure where it is going wrong... the `metadata$FAB` I ran is in character format. Check that it is also the same for you, and the read table did not force the string as factor. – Adam Quek Jul 11 '22 at 12:42
  • 1
    okay ..let me run....that class `metadata$FAB` I see in my R its in factor ..need to change that.. – PesKchan Jul 11 '22 at 12:44
  • 1
    Thank you @Adam it my 6 hours of search ends with your 4 line of code although i did find long way of doing through ggplot2 but it was too much code..this is simple thanks again.. – PesKchan Jul 11 '22 at 12:48
  • 2
    No problem. I'd learned something myself. :D – Adam Quek Jul 11 '22 at 12:49
  • 1
    Glad you got it resolved. Thanks Adam for taking a look and giving a solution :) – Tal Galili Jul 11 '22 at 13:25
  • @AdamQuek any thoughts on this https://stackoverflow.com/questions/72958698/adding-group-information-to-3d-plot-in-factoextra is it hard-coded ? or it can be modified since the pakacgae manager is not active in github for quite sometimes – PesKchan Jul 16 '22 at 05:10
  • Not used factoextra before (only FactoMineR). But if you are trying to run unsupervised clustering over dimension reduction ordination (pca), wouldn't it be better to stick with more conventional approaches, e.g. k-means clustering? See some of the discussion at cross-validated e.g. https://stats.stackexchange.com/questions/235946/pca-before-cluster-analysis – Adam Quek Jul 16 '22 at 05:33