I have values ranging from 0.105 to 15.589 representing fold change in gene expression. I've tried splitting these into bins using
df$bin <- cut(df$FC, breaks=c(seq(min(df$FC),max(df$FC),length.out = 50)))
giving me 50 bins containing different numbers of genes, e.g 4297 genes (their fold change) fall into the first bin (0.105,0.421], whereas only 1 gene falls into the the last bin (15.3,15.6].
Is there a way to split my range of fold changes into bins of equal group size, say 20. The last bin would probably contain less than 20 genes as it's unlikely to divide equally into groups of 20, but that's fine. Thanks!
If you set the breaks to be the quantiles of the target vector like this you'll get 50 equally sized (roughly) groups:
cut(df$FC, quantile(df$FC, probs = seq(0,1,l=51)))