I have an R data frame with four columns:
- sample
- miRNA
- x
- y
I would like to produce correlation plots for x and y faceted by miRNA using ggplot2. I would also like a separation of plots into two sections based on the direction of correlation, so that all plots showing positive correlation are in the top section and all plots showing negative correlation are in the bottom section.
Using facet_wrap I can't find a way to insert this kind of break, at least not in a way that could be generally applied to different numbers of miRNAs - e.g. if there are 2 miRNAs with positive correlation and 7 with negative correlation it will draw a 3 x 3 grid where the top row contains a mix of positive and negative plots, whereas what I would want in this instance is a top row with the 2 positive miRNAs and the 7 negative miRNAs in subsequent rows, with gaps where necessary so that all plots are the same size.
I thought using facet_grid might work. I added an extra column to the data frame called 'sign', a factor with levels 'Negative' and 'Positive', and then used plot + facet_grid(sign~miRNA)
, but this didn't work - all the negatively correlated miRNAs were displayed as empty graphs in the positive section and vice versa.
Apologies for the lack of images, I'm new here so unable to post them.