Copy Number Analysis
I have recently been using Karyoploter for plotting somatic copy number alterations.
I started doing this so that I could visualize gains and losses over multiple samples in a heatmap format. I hope that developing skills plotting with karyoploter will allow me to better visualize genomic data in an R environment.
Unfortunately, in order to plot multiple samples I need to do some for-loop hackery.
First, I define a function that plots segment data for an individual sample, plot_base_seg. This includes the basic karyoploter function kpPlotRegions. I also define a counter variable, tn which will define spacing between samples.
Then, I create a second function, plot_all_to_file which iterates over a grangeslist object of all samples, feeding each to plot_base_seg with purrr which outputs a pdf heatmap.

For attribution, please cite this work as
Stachelek (2020, Dec. 1). Kevin Stachelek, Ph.D.: Karyoploter for Somatic Copy Number Analysis. Retrieved from https://stchlk.rbind.io/posts/2020-12-01-karyoploter-for-somatic-copy-number-analysis/
BibTeX citation
@misc{stachelek2020karyoploter,
author = {Stachelek, Kevin},
title = {Kevin Stachelek, Ph.D.: Karyoploter for Somatic Copy Number Analysis},
url = {https://stchlk.rbind.io/posts/2020-12-01-karyoploter-for-somatic-copy-number-analysis/},
year = {2020}
}