Loading plot with R
0
1
Entering edit mode
9.4 years ago
Giffredo ▴ 10

Hi,

I have a problem concerning R code. I looking for a method to reach a loading plot. I made a scatter plot of my data. I used this code so far:

library(labdsv)
PCO.1<-pco(data.dist, k=2)
PCO.1
plot.pco(PCO.1)

I hope I gave all the information. Thank you in advance,

Giffredo

R • 4.2k views
ADD COMMENT
3
Entering edit mode

How did you get data.dist? What is the problem/error?

Did you try using just plot(PCO.1) instead of plot.pco(PCO.1)?

ADD REPLY
0
Entering edit mode

Hi, thanks for the reply!

This is the code used to reach the data.dist:

data=read.table("genere.txt", header=T, row.names=1, dec=".", sep="\t")
> dist.JSD <- function(inMatrix, pseudocount=0.000001, ...) {
+   KLD <- function(x,y) sum(x *log(x/y))
+   JSD<- function(x,y) sqrt(0.5 * KLD(x, (x+y)/2) + 0.5 * KLD(y, (x+y)/2))
+   matrixColSize <- length(colnames(inMatrix))
+   matrixRowSize <- length(rownames(inMatrix))
+   colnames <- colnames(inMatrix)
+   resultsMatrix <- matrix(0, matrixColSize, matrixColSize)
+   inMatrix = apply(inMatrix,1:2,function(x) ifelse (x==0,pseudocount,x))
+   for(i in 1:matrixColSize) {
+     for(j in 1:matrixColSize) {
+       resultsMatrix[i,j]=JSD(as.vector(inMatrix[,i]),
+                              as.vector(inMatrix[,j]))
+     }
+   }
+   colnames -> colnames(resultsMatrix) -> rownames(resultsMatrix)
+   as.dist(resultsMatrix)->resultsMatrix
+   attr(resultsMatrix, "method") <- "dist"
+   return(resultsMatrix)
+ }
> data.dist=dist.JSD(data)

I found this code in http://enterotype.embl.de/enterotypes.html

When the code below is inserted R gives me the coordinates to create a scatter plot without the coordinate to create the loading plot.

To be clearer:

I have same samples characterized by the % of different bacteria (the variables) present in them. I would like in the plot the samples and in the same time the bacteria in order to determine which samples are near to specific bacteria.

PCO.1<- pco(data.dist, k=2)
PCO.1

I tried the code plot(PCO.1) but I obtained the same results.. only the visualization of the samples.

Have a nice day!

Giffredo

ADD REPLY
0
Entering edit mode

Umm, so you want a plot like this?

< image not found >

ADD REPLY
0
Entering edit mode

mm... no actually... I would like a plot without cluster (don't care about it mow) but I want in the plot the samples, like here labeled with black point, and also the bacteria/enterotype that determine the position in the plot of the samples... In this way I could say if a sample is colse to a specific bacteria or not..

ADD REPLY
0
Entering edit mode

The plot you are talking about is essentially a clustering plot. It is same as the plot that I linked except for the circle.

Just a suggestion, you are posting answers instead of comments. When you want to reply to my comments, you can click on the add reply button below my comment and reply.

ADD REPLY
0
Entering edit mode

By the way, the R package ade4 can do exactly what you want. You may have to play with it though. Some good tutorials are here.

ADD REPLY

Login before adding your answer.

Traffic: 1487 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