Creating a new alphabet for use with `gglogo`


knitr::opts_chunk$set(fig.width = 6, fig.height = 4, fig.align='center', dev = "png")

By default, the `gglogo` package uses polygons created from a Helvetica font to use for creating logo plots. These polygons are stored in the object `alphabet.rda`, and use the name of the letter or digits they describe as their group identifier:


Each letter and digit is scaled to an area between 0 and 1 in y direction (which makes the lower case letter 'c' as tall as its upper case counterpart). In x direction the letter scaled proportionally to its extent in y direction.

qplot(x, y, geom="polygon", data=alphabet) + 
  facet_wrap(facets=~group, ncol=13) +

In order to change the alphabet used, an alphabet object has to be created, and the link to the object has to be changed so that the logo plots use the correct alphabet in the rendering process.

Creating a new alphabet

The function createPolygons have parameters to choose the font family and the set of letters for which polygons are supposed to be created. The parameters dim and fontsize are only needed, if some letters appear to be chopped off. In that case, the dimension of the image should be increased and/or fontsize should be decreased.

alphas <- c(LETTERS, letters, 0:9)
alphabet_garamond <- createPolygons(alphas, font="Garamond")
alphabet_garamond$group <- factor(alphabet_garamond$group, levels=alphas)

qplot(x,y, geom="polygon", data=alphabet_garamond,  group="pathGroup") +
  facet_wrap(facets=~group, ncol=13)
alphas <- c(LETTERS, letters, 0:9)
alphabet_helvetica <- createPolygons(alphas, font="Helvetica")
alphabet_helvetica$group <- factor(alphabet_helvetica$group, levels=alphas)

qplot(x,y, geom="polygon", data=alphabet_helvetica) +
  facet_wrap(facets=~group, ncol=13)

For use as alphabet in the logo geom, letters have to be scaled to fill the full extent in y-direction so as to fill the surrounding rectangles. Setting the parameter scale to TRUE regulates this.

alphas <- c(LETTERS, letters, 0:9)
alphabet_comic <- createPolygons(alphas, font="Comic Sans MS", scale=TRUE)
alphabet_comic$group <- factor(alphabet_comic$group, levels=alphas)

qplot(x,y, geom="polygon", data=alphabet_comic,  group="pathGroup") +
  facet_wrap(facets=~group, ncol=13)

Logo plot of peptide sequences, first with the unscaled Helvetica alphabet:

ggplot(data=ggfortify(sequences, seq="peptide", treatment="class")) +
  geom_logo(aes(x = class, y = bits, label=element, group=element, 
                fill = interaction(Polarity, Water)), 
            alphabet = alphabet_braille, 
            alpha = 0.8) +
  facet_wrap(~position) +

Try the gglogo package in your browser

Any scripts or data that you put into this service are public.

gglogo documentation built on May 30, 2017, 3:40 a.m.