Question

I have two dataframes which are RMA normalized as

  set.seed(1) 
  X <- data.frame(matrix(rnorm(20), nrow=10))
  Y <- data.frame(matrix(rnorm(20), nrow=10))

The columns are the gene expression levels and the rows are the genes. How to plot the density distribution of covariance of gene expression levels of X and distribution of covariance of gene expression levels Y in a single plot. It is something like this but I would like to study the distribution of the entire dataframe than columns.enter link description here

I tried using

       plot (density(X), col="red",ylim=c(0,3.5),xlim=c(-1,2)) 
       lines (density(Y), col="green") 

But I get an error

       Error in density.default() : argument 'x' must be numeric
Was it helpful?

Solution

I am still not sure, I understand you correctly.

set.seed(1) 
X <- data.frame(matrix(rnorm(20), nrow=10))
Y <- data.frame(matrix(rnorm(20), nrow=10))

#CV
d1 <- density(sapply(X, function(x) sd(x)/mean(x)))
d2 <- density(sapply(Y, function(x) sd(x)/mean(x)))

plot(d1, ylim=c(0,max(d1$y,d2$y)), xlim=range(d1$x,d2$x), col="green", xlab="", main="")
par(new=TRUE)
plot(d2, ylim=c(0,max(d1$y,d2$y)), xlim=range(d1$x,d2$x), col="red", xlab="", main="")
par(new=FALSE)

#covariance
d3 <- density(cov(X))
d4 <- density(cov(Y))

plot(d3, ylim=c(0,max(d3$y,d4$y)), xlim=range(d3$x,d4$x), col="green", xlab="", main="")
par(new=TRUE)
plot(d4, ylim=c(0,max(d3$y,d4$y)), xlim=range(d3$x,d4$x), col="red", xlab="", main="")
par(new=FALSE)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top