gggenes icon indicating copy to clipboard operation
gggenes copied to clipboard

ggGenes - Increase Text Size?

Open jvanbelzen opened this issue 3 years ago • 3 comments

I’m using ggGenes to build a simple gene illustration that I intend to pair with a metagene plot (see attached). I’m having trouble increasing the text size of the gene name, which should be controlled by geom_gene_label(). I’ve reviewed documentation for ggGenes and ggFitText, and haven’t been able to come up with any solutions. Have any advice?

I’ve tried:

  1. Setting geom_gene_label(grow=TRUE)
  2. Setting geom_gene_label(aes(size=10). Strangely, setting any value to size= results in a slight shrinkage of the text size.

Tried both of the above alone and in combination with: 3) Increasing the size of geom_gene_arrow() so that large text size can fit. Excessively large arrows still do not result in increased text size.

Code Sample

gene_arrows <- data.frame(
  start = c(24),
  end = c(72),
  molecule = c("BY4741"),
  gene = c("ADE5,7")
)

ggplot_genearrows <- ggplot(gene_arrows, aes(xmin = start, xmax = end, y = molecule, fill = gene)) +
  geom_gene_arrow(arrowhead_height = unit(12, "mm"), arrowhead_width = unit(6, "mm"), arrow_body_height = grid::unit(6, "mm")) +
  geom_gene_label(grow=TRUE, aes(label = gene)) +
  xlim(0,95) +
  scale_fill_brewer(palette = "Set3") +
  theme_genes() +
  theme(axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.line.x=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks.y=element_blank(),
        axis.title.y=element_blank(),
        legend.position="none"
  )

Thank you for taking the time to create a package for visually displaying genes in ggplot - it’s something I’ve looked for in the past!

jvanbelzen avatar May 20 '21 14:05 jvanbelzen

Thanks for reporting this! There are a few things going on here:

  • The size of the gene label text is affected by multiple parameters, which can understandably be quite confusing:
    • First, there is the invisible 'box' in which the text is allowed to be drawn. The width of the box is set by the xmin/xmax aesthetics which are shared with geom_gene_arrow(). The height is set by the height argument to geom_gene_label(), which by default is 3 mm (the default height of a geom_gene_arrow() arrow).
    • Then there are the padding.x and padding.y arguments, which define some additional padding space inside the box to prevent the text from bumping up against the edges.
    • Once the box and padding are defined, there are further parameters like grow and size which will determine how ggfittext manipulates the text to make it fit in the box.
  • There was a bug in both geom_gene_label() and geom_subgene_label() which would cause the height argument to be ignored. I've just pushed a new development version which fixes this bug (0.4.1.9003). This wasn't a cause of your issue, as you weren't using height, but it does affect the correct solution to the problem! You can install the new version with devtools::install_github("wilkox/gggenes").

With the new version installed, here's how you can get the text to fill the gene arrow:

library(ggplot2)
library(gggenes)
packageVersion("gggenes")
#> [1] '0.4.1.9003'

gene_arrows <- data.frame(
  start = c(24),
  end = c(72),
  molecule = c("BY4741"),
  gene = c("ADE5,7")
)

ggplot(gene_arrows, aes(xmin = start, xmax = end, y = molecule, label = gene)) +
  geom_gene_arrow(
    arrowhead_height = grid::unit(12, "mm"),
    arrowhead_width = grid::unit(6, "mm"),
    arrow_body_height = grid::unit(6, "mm")
  ) +
  geom_gene_label(height = grid::unit(6, "mm"), grow = TRUE)

Created on 2021-06-01 by the reprex package (v1.0.0)

The key is setting the height argument of geom_gene_label() to the same value as the arrow_body_height argument to geom_gene_arrow().

Hope this helps!

wilkox avatar Jun 01 '21 01:06 wilkox

Hi! I was having the same issue as OP and installing the development version and then setting the height arguments worked perfectly for me. I was wondering if this version is the one in the current conda version of this package, since I am using it on a Docker container built with a conda environment. Thank you very much for your time and sorry if this is an unrelated question to this issue!

ctuni avatar Jun 14 '21 14:06 ctuni

@ctuni I'm not very familiar with conda, but looking at the condo-forge repo it appears to be building from the most recent CRAN release (0.4.1) rather than the development version.

wilkox avatar Jun 15 '21 00:06 wilkox