Question: Adding text to ideogram in ggbio (or other method recommendations)?
4
gravatar for Alexander Skates
3.7 years ago by
United Kingdom
Alexander Skates340 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:

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:

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.1k views
ADD COMMENTlink modified 22 months ago by bernatgel1.9k • written 3.7 years ago by Alexander Skates340
4
gravatar for bernatgel
22 months ago by
bernatgel1.9k
Barcelona, Spain
bernatgel1.9k 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 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 COMMENTlink written 22 months ago by bernatgel1.9k
Please log in to add an answer.

Help
Access

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