Question: Error in correlation plot display in R

0

sonayuv •

**0**wrote: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

50k50k• written 3 months ago by sonayuv •0Hi @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

50k• written 3 months ago by antonioggsousa •50The previous solution presented by @Kevin Blighe is much more elegant!

António

50Obrigado / 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.

50kHi @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.

0Does my code work? (see below)

50kWhich 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

50The 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.

0Can 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!

50