This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Ggbio Issues: How To Align Tracks & Where Are Figure Legends?

Dear Biostar users,

I am using ggbio to add a chromosome ideogram over data along the length of a chromosome. See the code beneath here for some sample code:

library(GenomicRanges)
library(ggbio)
data(hg19IdeogramCyto, package = "biovizBase")
x <- seq(from=1,to=8e+07,by=100)
x <- sample(x,7000)
x <- append(x,x)
y_ <- seq(from=-1,to=1,by=0.00001)
y <- sample(y_,7000)
y2 <- sample(y,7000)
y <- append(y,y2)
z <- NULL
z[1:7000] <- 'one'
z[7001:14000] <- 'two'
df <- data.frame(x,y,z)
p <- plotSingleChrom(hg19IdeogramCyto, "chr17",xlabel=TRUE,zoom.region=c(min(df$x),max(df$x)))
p2 <- qplot(x,y,data=df,colour=z,geom='line')
tracks(p, p2 = p2, heights = c(1.2, 5))

Which results in:

enter image description here

Issue one: the ideogram x axis seems out of place with the data x axis. How do I align these two, in such a way that the cytobands actually corresprond to x axis below?

Issue two: Where have my legends gone? In normal ggplot/qplot I would nicely get a legend with "one" and "two" on the right. Somehow this vanished?

Thanks a lot for any suggestions!

r

1 answer

I just tried this code using BioC 3.2

> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.3 LTS

...

other attached packages:

[1] ggbio_1.18.3         ggplot2_2.0.0        GenomicRanges_1.22.4
[4] GenomeInfoDb_1.6.3   IRanges_2.4.6        S4Vectors_0.8.11
[7] BiocGenerics_0.16.1

I had to change

p <- plotSingleChrom(hg19IdeogramCyto, "chr17",xlabel=TRUE,zoom.region=c(min(df$x),max(df$x)))

to

p <- Ideogram(hg19IdeogramCyto, "chr17",xlabel=TRUE,zoom.region=c(min(df$x),max(df$x)))

It did give the error

`axis.ticks.margin` is deprecated. Please set `margin` property  of `axis.text` instead

but produced the graph as expected (?)

Log in to answer this question.