我有92套同类数据。
我想为这两种组合提供一个相关矩阵。
i.e.,我希望有一个92x92
的矩阵。
此种内容(ci
,cj
)应当与ci
和cj
相关。
我如何这样做?
我有92套同类数据。
我想为这两种组合提供一个相关矩阵。
i.e.,我希望有一个92x92
的矩阵。
此种内容(ci
,cj
)应当与ci
和cj
相关。
我如何这样做?
例如:
d <- data.frame(x1=rnorm(10),
x2=rnorm(10),
x3=rnorm(10))
cor(d) # get correlations (returns matrix)
您可使用校准包。
d <- data.frame(x1=rnorm(10),
x2=rnorm(10),
x3=rnorm(10))
M <- cor(d) # get correlations
library( corrplot ) #package corrplot
corrplot(M, method = "circle") #plot matrix
详情见:http://cran.r-project.org/web/parages/corrplot/vignettes/corrplot-intro.html>。
The cor function will use the columns of the matrix in the calculation of correlation. So, the number of rows must be the same between your matrix x and matrix y. Ex.:
set.seed(1)
x <- matrix(rnorm(20), nrow=5, ncol=4)
y <- matrix(rnorm(15), nrow=5, ncol=3)
COR <- cor(x,y)
COR
image(x=seq(dim(x)[2]), y=seq(dim(y)[2]), z=COR, xlab="x column", ylab="y column")
text(expand.grid(x=seq(dim(x)[2]), y=seq(dim(y)[2])), labels=round(c(COR),2))
此处是按单一矩阵计算的相关矩阵的海关行号及栏目标签的例子:
png("corplot.png", width=5, height=5, units="in", res=200)
op <- par(mar=c(6,6,1,1), ps=10)
COR <- cor(iris[,1:4])
image(x=seq(nrow(COR)), y=seq(ncol(COR)), z=cor(iris[,1:4]), axes=F, xlab="", ylab="")
text(expand.grid(x=seq(dim(COR)[1]), y=seq(dim(COR)[2])), labels=round(c(COR),2))
box()
axis(1, at=seq(nrow(COR)), labels = rownames(COR), las=2)
axis(2, at=seq(ncol(COR)), labels = colnames(COR), las=1)
par(op)
dev.off()
There are other ways to achieve this here: (Plot correlation matrix into a graph), but I like your version with the correlations in the boxes. Is there a way to add the variable names to the x and y column instead of just those index numbers? For me, that would make this a perfect solution. Thanks!
编辑:我试图通过[在盒子里的马克]就这个职位发表评论,但我显然不知道我做什么。 然而,我确实设法为自己回答这一问题。
if d is the matrix (or the original data frame) and the column names are what you want, then the following works:
axis(1, 1:dim(d)[2], colnames(d), las=2)
axis(2, 1:dim(d)[2], colnames(d), las=2)
激光=0将姓名贴回正常位置,地雷很长,因此我用激光=2将其排在轴上。
edit2: to suppress the image() function printing numbers on the grid (otherwise they overlap your variable labels), add xaxt= n , e.g.:
image(x=seq(dim(x)[2]), y=seq(dim(y)[2]), z=COR, col=rev(heat.colors(20)), xlab="x column", ylab="y column", xaxt= n )
This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...
since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...
I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...
I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...
I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...
I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...
Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...
I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...