Is there a way to convert “dist” to “data.frame”?
1
2
Entering edit mode
3.2 years ago
Riku ▴ 80

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 • 5.5k views
ADD COMMENT
2
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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!

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
2
Entering edit mode
3.2 years ago
Basti ★ 2.0k

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.

ADD COMMENT

Login before adding your answer.

Traffic: 1552 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6