Question: Adding text to ideogram in ggbio (or other method recommendations)?
gravatar for Alexander Skates
4.5 years ago by
United Kingdom
Alexander Skates350 wrote:

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:


#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" <- read.table(avs.file,header=F,sep="\t",stringsAsFactors=F)
avs.granges <- GRanges([,1],
elementMetadata(avs.granges) <-[,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")

which gives me this:

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!


snp ideogram ggbio image • 3.6k views
ADD COMMENTlink modified 2.6 years ago by bernatgel2.4k • written 4.5 years ago by Alexander Skates350
gravatar for bernatgel
2.6 years ago by
Barcelona, Spain
bernatgel2.4k wrote:

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 but using your data you can simply use

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 COMMENTlink written 2.6 years ago by bernatgel2.4k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1782 users visited in the last hour