ggbio - change transcript label sizes
1
0
Entering edit mode
Kevin Blighe ★ 4.0k
@kevin
Last seen 26 days ago
Republic of Ireland

It seems next to impossible to change the size of the geom_text() labels with autoplot() in ggbio. For example, take the reproducible code:

require(ggbio)
require(GenomicRanges)
require(Mus.musculus)

p <- autoplot(
  Mus.musculus, # OrganismDb class
  which = GRanges("chr12", IRanges(116052334, 116929233)),
  columns = c("SYMBOL"),
  gap.geom = 'chevron')
p

sss

The label sizes are too small. So, I figured that something like this would work:

p + geom_text(size = 16)

However, that doesn't change the size.

I also tried (before running autoplot()) to set defaults for geom_text(), but that neither works:

update_geom_defaults("text", list(colour = "black", size = 20))

I also tried to create a custom function and specify label.text.cex, but it neither works:

theme_tracks_custom <- function (bg = "#fffedb", alpha = 1, ...) {
  res <- theme_clear(grid.x.major = FALSE, ...)
  attr(res, "track.plot.color") <- sapply(bg, scales::alpha, alpha)
  attr(res, "track.bg.color") <- bg
  attr(res, "label.text.color") <- "white"
  attr(res, "label.bg.fill") <- "#a52a2a"
  attr(res, 'label.text.cex') <- 3
  res
}
p + theme_tracks_custom()

All of the autoplots that I have seen via Google Images have these small labels; so, I figured that nobody else neither found a way to change them.

One issue is that the global text size attribute for ggplot2's theme() is not carried through to geom_text(), which has its own text size attribute.

In the ideal situation, autoplot() would permit the user to specify the label size that is then passed to geom_text(), and also permit that check.overlap could be TRUE or FALSE

Kevin

ggbio annotation • 1.8k views
ADD COMMENT
0
Entering edit mode

Personally I firstly got the gene locacations from a file that I had locally:

        gene_data=read.table('ensembl_genes.v87.grch37.txt',sep='\t',header=T,stringsAsFactors=F)
        gene_data=gene_data[gene_data$gene_name==gene_of_interest,]

and then I used the geom_alignment() command where I was able to specify label.size

        library(TxDb.Hsapiens.UCSC.hg19.knownGene)
        data(genesymbol, package = "biovizBase")
        wh=GRanges(paste0('chr',gene_data$chr_name), IRanges(gene_data$start_pos, gene_data$end_pos))
        from=findOverlaps(genesymbol,wh)@from
        p.txdb=ggplot()+geom_alignment(txdb,which= wh, names.expr =genesymbol$symbol[from],cds.rect.h = 0.1,label.size=5)
ADD REPLY
1
Entering edit mode
@michael-lawrence-3846
Last seen 3.0 years ago
United States

The forthcoming version 1.33.2 supports a labels.size= argument for this purpose. Btw, you can always pass additional arguments that get passed down to different layers. Passing size= is problematic, because it also affects the lines. But you can pass check_overlap= without issues.

ADD COMMENT
0
Entering edit mode

Great - thanks for the information, Michael.

ADD REPLY

Login before adding your answer.

Traffic: 707 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