Now for something different: Using R to make oncoplots
Wednesday, April 1st, 2026 01:21 pmI'm sure someone much better at using R to make beautiful figures would have figured out how to create an oncoplot easily, even when the data is not in a MAF or VCF format (it's CSV).
Anyway, thanks to the combined power of ggplot2 and patchwork, I was able to create what my collaborator wanted for the paper he's writing on this data, and so in case I ever forget it and in case it's ever useful for anyone, here are some links that I've referenced:
For data prep, I arranged the data by the order of frequency of the gene mutation (highest to lowest), gave all the sample a new ID based on this order and used that new ID for the x-axis for all the figures I made so that they correspond to each other.
Using patchwork, I made it so that the figures for ethnicity, age category, etc. were a lot thinner in terms of width compared to the gene plot. I didn't make a stacked bar chart as shown in the oncoplot example because it was already represented by another figure elsewhere, but if I had wanted to do it, it shouldn't be hard using these two packages.
I don't know why I spent two days trying to wrangle other packages specifically for oncoplots when this solution just took me half an hour, tops. But I guess one has to go through all that pain before deciding to ditch those solutions and go with what's already familiar and known to me (that is, ggplot2).
Anyway, thanks to the combined power of ggplot2 and patchwork, I was able to create what my collaborator wanted for the paper he's writing on this data, and so in case I ever forget it and in case it's ever useful for anyone, here are some links that I've referenced:
- ggplot2 to make heatmaps: I used this to make (1) heatmaps for the genes; (2) heatmap for ethnicity, age category, smoking history, etc. all separately
- patchwork to combine plots: Then I combined them all, collected all the legend to the side and done! This was a pretty useful guide as well.
For data prep, I arranged the data by the order of frequency of the gene mutation (highest to lowest), gave all the sample a new ID based on this order and used that new ID for the x-axis for all the figures I made so that they correspond to each other.
Using patchwork, I made it so that the figures for ethnicity, age category, etc. were a lot thinner in terms of width compared to the gene plot. I didn't make a stacked bar chart as shown in the oncoplot example because it was already represented by another figure elsewhere, but if I had wanted to do it, it shouldn't be hard using these two packages.
I don't know why I spent two days trying to wrangle other packages specifically for oncoplots when this solution just took me half an hour, tops. But I guess one has to go through all that pain before deciding to ditch those solutions and go with what's already familiar and known to me (that is, ggplot2).