Color label of rainfall plot drawn by KaryoploteR

You can use the standard legend() command as outlined in this issue here: support.bioconductor.org/p/124328/

Minimal example based on bernatgel.github.io/karyoploter_tutorial//Examples/Rainfall/Rainfall.html :

library(karyoploteR)


somatic.mutations <- read.table(file="ftp://ftp.sanger.ac.uk/pub/cancer/AlexandrovEtAl/somatic_mutation_data/Pancreas/Pancreas_raw_mutations_data.txt", header=FALSE, sep="t", stringsAsFactors=FALSE)
somatic.mutations <- setNames(somatic.mutations, c("sample", "mut.type", "chr", "start", "end", "ref", "alt", "origin"))

somatic.mutations <- split(somatic.mutations, somatic.mutations$sample)
sm <- somatic.mutations[["APGI_1992"]]
sm.gr <- toGRanges(sm[,c("chr", "start", "end", "mut.type", "ref", "alt")])
seqlevelsStyle(sm.gr) <- "UCSC"

variant.colors <- getVariantsColors(sm.gr$ref, sm.gr$alt)
kp <- plotKaryotype(plot.type=4)
kpPlotRainfall(kp, data = sm.gr, col=variant.colors)
uniq_cols <- variant.colors[!duplicated(variant.colors)]
legend(x = "bottomright", fill=uniq_cols, legend=names(uniq_cols))

Now you can customise the call to legend() in any way you like.

Looks like this:example rainbow plot

Read more here: Source link