Adding text to ideogram in ggbio (or other method recommendations)?
1
4
Entering edit mode
8.7 years ago

I have a bed file with the chromosomal coordinates of some snps and their RsIds, e.g.

chr1    202187176    202187176    rs6678914
chr14    68660428    68660428    rs2588809
chr6    13722523    13722523    rs204247
chr4    175846426    175846426    rs6828523
chr20    32588095    32588095    rs2284378
..

I want to plot these on an ideogram, and so far I have been able to do this with ggbio:

library(ggbio)
library(GenomicRanges)

#load banding data
data(hg19IdeogramCyto, package = "biovizBase")
hg19 <- keepSeqlevels(hg19IdeogramCyto, paste0("chr", c(1:22, "X", "Y")))

#read the SNPs BED file in to granges object
avs.file <- "IndexMarker.bed"
avs.data <- read.table(avs.file,header=F,sep="\t",stringsAsFactors=F)
avs.granges <- GRanges(seqnames=avs.data[,1],
                       ranges=IRanges(start=avs.data[,2],
                                     end=avs.data[,3]),
                             strand="*")
elementMetadata(avs.granges) <- avs.data[,4]
avs.granges <- keepSeqlevels(avs.granges, paste0("chr",c(1:22)))
seqlengths(avs.granges) <- seqlengths(hg19Ideogram)[names(seqlengths(avs.granges))]

data(hg19Ideogram, package = "biovizBase")

#plot the ideogram
p <- ggplot(hg19) + layout_karyogram(cytoband = TRUE)
p <- p + layout_karyogram(avs.granges, geom = "rect", ylim = c(11, 21), color = "red")
p

which gives me this:

image: plot

However, I would also like to annotate it with the RsIds. How do I add text to these plots (so each dash indicating a variant also has the respective rs id)?

Alternative suggestions for generating such a diagram are welcome!

ideogram ggbio SNP • 5.1k views
ADD COMMENT
4
Entering edit mode
6.9 years ago
bernatgel ★ 3.4k

This is an old thread, but posting in case anyone has the same problem.

You can use karyoploteR instead of ggbio to easily achieve this. You can find a detailed example with genes instead of snps at https://bernatgel.github.io/karyoploter_tutorial//Examples/PlotGenes/PlotGenes.html but using your data you can simply use

library(karyoploteR)
snps <- read.table(file="snps.txt", sep="\t", stringsAsFactors = FALSE)
kp <-plotKaryotype()
kpPlotMarkers(kp, data=toGRanges(snps), labels=snps[,4], text.orientation = "horizontal", cex=1.3, r1=0.5)

enter image description here

ADD COMMENT

Login before adding your answer.

Traffic: 2292 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6