This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Is there a way to convert “dist” to “data.frame”?

Hi, all.

I will output MDS plot with ggplot2.

But, I couldn’t read the data because the class of the data wasn’t support in ggplot2. Is there a way to convert “dist” to “data.frame”?

Although I tried “as.data.frame()“, I was not able to do. The following error messages was outputed.

> as.data.frame(d)
Error in as.data.frame.default(d) : 
  cannot coerce class ‘"dist"’ to a data.frame

I'm a beginner in bioinformatics, so sorry for the basic question. Could you please advise me? Thank you very much for your appreciated!

mds ggplot2 rnaseq

Note that there are plotMDS functions also in limma and edgeR that can make these plots directly from the normalized count data, but of course ggplot2 has the most appealing graphics.

I'd say the short answer is that you need to pass by as.matrix first: as.data.frame(as.matrix(d))

I was able to do it.

But, I can't make a graph Converting the distance matrix to dataframe type by this operation was not enough to output the MDS plot.

I will try another method. Thank you for your answer!

1 answer

You have a specific function designed to perform this in the metagMisc package :

devtools::install_github("vmikk/metagMisc")
library("metagMisc")
dist2list(d, tri = TRUE)

You have also plenty other solutions as you may find here.

Log in to answer this question.