Entering edit mode
5.4 years ago
sonayuv
•
0
I used the following code to get a correlogram of 326 genes. I have the pairwise correlation values. I wanted to represent them in a plot.
> library(readxl)
> pears <- read_excel("PATH/pears.xlsx")
> View(pears)
> library(corrplot)
corrplot 0.84 loaded
> corrplot(pears, method="circle")
Error in matrix(if (is.null(value)) logical() else value, nrow = nr, dimnames = list(rn, :
length of 'dimnames' [2] not equal to array extent
Please help to resolve.
What is the output of
Hi @sonayuv,
If you have a square (symmetric) correlation matrix, where columns and rows correspond to some correlation metric that you have used, the problem is related with your input to the function "corrplot()".
When you import data from excel with "read_excel" function, your data belongs to the tibble class. Well the function "corrplot()" requires data matrix, not a tibble. Check the class of your data with "class(pears)". So, you have to convert your tibble data frame into a matrix in order to you use the function corrplot.
you may lose your row names in the last code, so restore them follow the next code
restore the row names
Plot your correlograma
I hope this helps! Sincerely, António
The previous solution presented by @Kevin Blighe is much more elegant!
António
Obrigado / thanks, António. In your answer, you also explain the reason why the user's code did not work (due to it being a tibble); so, that is good.
Hi @Antonio, Thank you. Running the above mentioned statement gave me the following error.
Error in dimnames(x) <- dn : length of 'dimnames' [1] not equal to array extent
Please assist.
Does my code work? (see below)
Which is the result of:
I think you may not have a symmetric table. You still might plot your correlogram without running that command. Although I think your table is not symmetric and you may face some problems.
Try the solution proposed by @Kevin Blighe. It may solve your problems!
António
The table is not symmetric it seems. But there are 326 genes names on the first row and column with A1 cell having "genename" in it.
Can you do print of the header of your table?
Try:
I think that your column names are the first row. If they are in the first row, you need to exclude them by using:
This last command will exclude the first row of pears.
I hope that this helps!