heatmap 2 error
1
0
Entering edit mode
6.4 years ago
Sam ▴ 150

When I try to run the heatmap2 for my dataset of log2 FC , I got 'x' must have at least 2 rows and 2 columns error, how I can solve this error for my dataset matrix?

Thanks

id               log2FoldChange
mir-120a-5p -5.900679019
mir-190b-3p 2.8326859513
mir-173-5p   2.9164912341
mir-21d   -2.447722216
heatmap • 5.5k views
ADD COMMENT
1
Entering edit mode
6.4 years ago

Yes, as the error states, a heatmap requires at least 2 rows and 2 columns. Here, you are just trying to plot log (base 2) fold changes, which would be better represented by a simple plot()

If you want to create a heatmap of your list of mirs of interest, then you have to filter your original expression data-matrix with the IDs of the mirs of interest, and then re-run the heatmap function on the sub-set of this expression matrix.

ADD COMMENT
0
Entering edit mode

Hi Kevin, I'm new in R, could you explain a bit more about filter of mir id's?

ADD REPLY
1
Entering edit mode

you are plotting rownames against one column so this is not a heatmap rather just a plot of points corresponding to your miRNA id's. So if you want to plot a heatmap either you should make a matrix or dataframe in R for the ID that you are interested, pull the corresponding normalized expression values(this can be TPM, logCPM, RPKM(single end), FPKM(paired-end) for those genes for all your samples on which this log2FoldChange are estimated and then plot the heatmap.

The above will produce a matrix for x rownames (genes) across different y (samples/replicates having values that encompass your condition of interest on which differential expression analysis was performed).

This data frame can be imported into R and then you can perform your heatmap with preferrable heatmap tools in R.

ADD REPLY
1
Entering edit mode

Hi Sam, as vchrs implies, you first need to save your mir IDs of interest in a vector.

Then, you can subset your original data matrix with something like: MyMatrixOfInterestingMirs <- MyMatrix[ MyInterestingMirs, ]

Then: hearmap.2(data.matrix(MyMatrixOfInterestingMirs)

Your vector of interesting mirs will be stored in MyInterestingMirs in this example.

ADD REPLY
0
Entering edit mode

Thanks in advance Kevin, could you also help me in command for volcano plot( log2 fold change vs. -log2 P-value)? some thing like this link : https://www.researchgate.net/figure/6680131_fig4_Volcano-plots-log2-fold-change-vs-log2-P-value-A-gene-was-identified-as

ADD REPLY
0
Entering edit mode

You can take my code from here for a very simple volcano plot: A: Volcano Plot from DEseq2 (scroll down a bit).

I have other more complex code that does a very good job for producing a volcano plot, but I have not yet shared it on Biostars.

ADD REPLY
0
Entering edit mode

I introduced the out put of deseq2 as input matrix wit this command :

 res <- read.table ("~/DE_expression_miRNA", header=T, sep=",")
cols <- densCols(res$log2FoldChange, -log10(res$pvalue))

but I got this error: Error in Math.factor(res$pvalue) : ‘log10’ not meaningful for factors

ADD REPLY
1
Entering edit mode

Try it with stringsAsFactors=FALSE in read.table, and then ensure that the pvalues are numeric with as.numeric:

res <- read.table ("~/DE_expression_miRNA", header=T, sep=",", stringsAsFactors=FALSE)
cols <- densCols(res$log2FoldChange, -log10(as.numeric(res$pvalue)))
ADD REPLY
0
Entering edit mode

with removing n/a padj problem solved and I got plot but instead of miR name , each dot labeled by row number , how I can replace them with each miR name ?

ADD REPLY
0
Entering edit mode

Ideally your object res should have mirs as the rownames? Then they will automatically be used by heatmap.2 for labeling.

Otherwise, you can explicitly specify labels with the labRow and labCol parameters of heatmap.2 (in these situations, the order of the names that you use have to match the order of rows and columns in the data-matrix on which the heatmap is being generated).

ADD REPLY
0
Entering edit mode

this is my input matrix with mirname :

id,baseMean,log2FoldChange,lfcSE,stat,pvalue,padj
mir-10a-5p,43132.8824542284,-5.900679019,0.7586849901,-7.7775085786,7.39667555984345E-15,4.54895546930372E-12
ADD REPLY
0
Entering edit mode

No, the input matrix has to be just a matrix of expression values, with (usually) genes as rows and samples as columns. The pasted data in your above comment is the results of a differentially expression analysis, which would have been performed on your matrix of expression values.

You use the differential expression results to find statistically significant mirs/genes, and then filter your matrix of express values based on these.

I'm not sure that there's a tutorial on Biostars for heatmaps, but take a look at this one in order to get the general idea: https://www2.warwick.ac.uk/fac/sci/moac/people/students/peter_cock/r/heatmap/

ADD REPLY
0
Entering edit mode

I used above data to draw volcano plot , and I want to label volcano dot with miR names.

ADD REPLY
0
Entering edit mode

Ah, apologies! I'm involved in numerous threads/questions and forgot that we had moved onto the volcano plot. To add labels, use the line that I commented out in my code ont he page to which I linked.

If you have further issues, it may be useful to open a new question, as this question was originally about heatmaps.

ADD REPLY

Login before adding your answer.

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