{"id":13711314,"url":"https://github.com/wilkox/gggenes","last_synced_at":"2025-04-04T23:09:46.535Z","repository":{"id":37430881,"uuid":"83646997","full_name":"wilkox/gggenes","owner":"wilkox","description":"➡️️➡️️⬅️️➡️️ Draw gene arrow maps in ggplot2","archived":false,"fork":false,"pushed_at":"2024-02-24T05:26:01.000Z","size":12550,"stargazers_count":529,"open_issues_count":10,"forks_count":48,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T22:14:20.979Z","etag":null,"topics":["genetics","ggplot2","r"],"latest_commit_sha":null,"homepage":"http://wilkox.org/gggenes","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wilkox.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-03-02T07:16:19.000Z","updated_at":"2025-03-28T15:33:54.000Z","dependencies_parsed_at":"2023-09-26T08:56:54.185Z","dependency_job_id":"d3f3cc6d-0fed-4d91-9d94-a89715c3c425","html_url":"https://github.com/wilkox/gggenes","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilkox%2Fgggenes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilkox%2Fgggenes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilkox%2Fgggenes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilkox%2Fgggenes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wilkox","download_url":"https://codeload.github.com/wilkox/gggenes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247261612,"owners_count":20910108,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["genetics","ggplot2","r"],"created_at":"2024-08-02T23:01:06.862Z","updated_at":"2025-04-04T23:09:46.502Z","avatar_url":"https://github.com/wilkox.png","language":"R","funding_links":[],"categories":["Plot layers","ggplot","Table of Contents","Static"],"sub_categories":["Domain-specific","Visualization"],"readme":"---\noutput:\n  github_document:\n    html_preview: true\n    fig_width: 8\n    fig_height: 8\n---\n\n```{r, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\"\n)\n```\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/wilkox/gggenes/workflows/R-CMD-check/badge.svg)](https://github.com/wilkox/gggenes/actions)\n[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/gggenes)](https://cran.r-project.org/package=gggenes)\n[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)\n\u003c!-- badges: end --\u003e\n\n# gggenes\n\ngggenes is a [ggplot2](https://ggplot2.tidyverse.org) extension for drawing\ngene arrow maps.\n\n## Installing gggenes\n\nInstall the stable version of gggenes from CRAN:\n\n`install.packages(\"gggenes\")`\n\nIf you want the development version, install it from GitHub:\n\n`devtools::install_github(\"wilkox/gggenes\")`\n\n## Drawing gene arrows with `geom_gene_arrow()`\n\n`geom_gene_arrow()` is a ggplot2 geom that represents genes with arrows. The\nstart and end locations of the genes within their molecule(s) are mapped to the\n`xmin` and `xmax` aesthetics respectively. These start and end locations are\nused to determine the directions in which the arrows point. The `y` aesthetic\nmust be mapped to the molecule(s). If you are drawing more than one molecule,\nand the numerical locations of the genes are not similar across molecules, you\nalmost certainly want to facet the plot with `scales = \"free\"` to avoid drawing\nridiculously large molecules with ridiculously tiny genes.\n\n```{r geom_gene_arrow}\nlibrary(ggplot2)\nlibrary(gggenes)\n\nggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene)) +\n  geom_gene_arrow() +\n  facet_wrap(~ molecule, scales = \"free\", ncol = 1) +\n  scale_fill_brewer(palette = \"Set3\")\n```\n\n## Beautifying the plot with `theme_genes`\n\nBecause the resulting plot can look cluttered, a ggplot2 theme `theme_genes`\nis provided with some sensible defaults.\n\n```{r theme_genes}\nggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene)) +\n  geom_gene_arrow() +\n  facet_wrap(~ molecule, scales = \"free\", ncol = 1) +\n  scale_fill_brewer(palette = \"Set3\") +\n  theme_genes()\n```\n\n## Aligning genes across facets with `make_alignment_dummies()`\n\nOften you will want a certain gene to be vertically aligned across the faceted\nmolecules. `make_alignment_dummies()` generates a set of dummy genes that if\nadded to the plot with `geom_blank()` will extend the range of each facet to\nvisually align the selected gene across facets.\n\n```{r make_alignment_dummies}\ndummies \u003c- make_alignment_dummies(\n  example_genes,\n  aes(xmin = start, xmax = end, y = molecule, id = gene),\n  on = \"genE\"\n)\n\nggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene)) +\n  geom_gene_arrow() +\n  geom_blank(data = dummies) +\n  facet_wrap(~ molecule, scales = \"free\", ncol = 1) +\n  scale_fill_brewer(palette = \"Set3\") +\n  theme_genes()\n```\n\n## Labelling genes with `geom_gene_label()`\n\nTo label individual genes, provide a `label` aesthetic and use\n`geom_gene_label()`. `geom_gene_label()` uses the\n[ggfittext](https://github.com/wilkox/ggfittext) package to fit the label text\ninside the gene arrows; see the ggfittext documentation for more details on how\nit resizes and reflows text to make it fit.\n\n```{r labelled_genes}\nggplot(\n    example_genes,\n    aes(xmin = start, xmax = end, y = molecule, fill = gene, label = gene)\n  ) +\n  geom_gene_arrow(arrowhead_height = unit(3, \"mm\"), arrowhead_width = unit(1, \"mm\")) +\n  geom_gene_label(align = \"left\") +\n  geom_blank(data = dummies) +\n  facet_wrap(~ molecule, scales = \"free\", ncol = 1) +\n  scale_fill_brewer(palette = \"Set3\") +\n  theme_genes()\n```\n\n## Reversing gene direction with the optional `forward` aesthetic\n\nBy default, genes arrows are drawn pointing in the direction implied by `xmin`\nand `xmax`. You can override this with the optional `forward` aesthetic, which\ncan be useful when the gene coordinates and orientation are encoded as separate\nvariables.\n\nIf `forward` is TRUE (the default), or any value that coerces to TRUE such as\n1, the gene will be drawn pointing in the implied direction, i.e. from `xmin`\nto `xmax`. If `forward` is FALSE, or any value that coerces to FALSE such as\n0, the gene will be drawn in the reverse of this implied direction:\n\n```{r reversing_direction}\nggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene, \n                          forward = orientation)) +\n  geom_gene_arrow() +\n  facet_wrap(~ molecule, scales = \"free\", ncol = 1) +\n  scale_fill_brewer(palette = \"Set3\") +\n  theme_genes()\n```\n\n## Viewing subgene segments\n\nWe can highlight subgene segments, such as protein domains or local alignments,\nusing `geom_subgene_arrow()`.\n\nThis works similarly to `geom_gene_arrow()`, but in addition to `xmin` and\n`xmax` (which determine the gene boundaries), we need the aesthetics `xsubmin`\nand `xsubmax` to determine the subgene boundaries. `geom_gene_arrow()` will\nproduce pretty arrowheads, as long as `xmin \u003e= xsubmin` and `xmax \u003e= xsubmax`\nfor all subgenes (subgenes that break gene boundaries will be skipped with a\nwarning).\n\nThe suggested usage is to use `geom_gene_arrow()` with no fill, and then add a\nsubgene layer over this:\n\n```{r subgenes}\nggplot(example_genes, aes(xmin = start, xmax = end, y = molecule)) +\n  facet_wrap(~ molecule, scales = \"free\", ncol = 1) +\n  geom_gene_arrow(fill = \"white\") +\n  geom_subgene_arrow(data = example_subgenes,\n    aes(xmin = start, xmax = end, y = molecule, fill = gene,\n        xsubmin = from, xsubmax = to), color=\"black\", alpha=.7) +\n  theme_genes()\n```\n\nTo label subgenes, we can use `geom_subgene_label()`, which works similarly to\n`geom_gene_label()` with the major difference that it requires `xsubmin` and\n`xsubmax` aesthetics (not `xmin` and `xmax`).\n\n```{r subgene_labels, fig.height = 2}\nggplot(subset(example_genes, molecule == \"Genome4\" \u0026 gene == \"genA\"),\n       aes(xmin = start, xmax = end, y = strand)\n  ) +\n  geom_gene_arrow() +\n  geom_gene_label(aes(label = gene)) +\n  geom_subgene_arrow(\n    data = subset(example_subgenes, molecule == \"Genome4\" \u0026 gene == \"genA\"),\n    aes(xsubmin = from, xsubmax = to, fill = subgene)\n  ) +\n  geom_subgene_label(\n    data = subset(example_subgenes, molecule == \"Genome4\" \u0026 gene == \"genA\"),\n    aes(xsubmin = from, xsubmax = to, label = subgene),\n    min.size = 0\n  )\n```\n\n## Drawing point genetic features\n\nWe can draw point genetic features, such as restriction sites or transcription\nstart sites, with `geom_feature()`, and label them with `geom_feature_label()`.\nBoth of these geoms take an optional `forward` aesthetic to indicate whether a\nfeature is oriented and, if so, in what direction (`TRUE` meaning oriented\ntowards the right and `FALSE` meaning towards the left).\n\n```{r}\nggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene, label = gene)) +\n  geom_feature(\n    data = example_features,\n    aes(x = position, y = molecule, forward = forward)\n  ) +\n  geom_feature_label(\n    data = example_features,\n    aes(x = position, y = molecule, label = name, forward = forward)\n  ) +\n  geom_gene_arrow() +\n  geom_gene_label() +\n  geom_blank(data = example_dummies) +\n  facet_wrap(~ molecule, scales = \"free\", ncol = 1) +\n  scale_fill_brewer(palette = \"Set3\") +\n  theme_genes()\n```\n\nWe can draw and label transcription terminators with `geom_terminator()` and\n`geom_terminator_label()`.\n\n```{r}\nggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene, label = gene)) +\n  geom_feature(\n    data = example_features,\n    aes(x = position, y = molecule, forward = forward)\n  ) +\n  geom_feature_label(\n    data = example_features,\n    aes(x = position, y = molecule, label = name, forward = forward)\n  ) +\n  geom_terminator(data = example_terminators, aes(x = position, y = molecule)) +\n  geom_terminator_label(data = example_terminators, \n                        aes(x = position, y = molecule, label = name)) +\n  geom_gene_arrow() +\n  geom_gene_label() +\n  geom_blank(data = example_dummies) +\n  facet_wrap(~ molecule, scales = \"free\", ncol = 1) +\n  scale_fill_brewer(palette = \"Set3\") +\n  theme_genes()\n```\n\n## Experimental: drawing in polar coordinates\n\nThe current development version introduces drawing in polar coordinates, by\nadding `coord_polar()` to the plot. This works with all gene, subgene, feature,\nand terminator geoms.\n\n```{r}\nggplot(example_genes_polar, aes(xmin = start, xmax = end, y = molecule, fill = gene, label = gene)) +\n  geom_feature(\n    data = example_features_polar,\n    aes(x = position, y = molecule, forward = forward)\n  ) +\n  geom_feature_label(\n    data = example_features_polar,\n    aes(x = position, y = molecule, label = name, forward = forward)\n  ) +\n  geom_terminator(data = example_terminators_polar, aes(x = position, y = molecule)) +\n  geom_terminator_label(data = example_terminators_polar, \n                        aes(x = position, y = molecule, label = name)) +\n  geom_gene_arrow() +\n  geom_gene_label() +\n  scale_fill_brewer(palette = \"Set3\") +\n  coord_polar() +\n  scale_y_discrete(limits = c(\"\", \"Genome6\", \"Genome1\"))\n```\n\n## Other genetic features\n\nDo you have an idea, suggestion or request for another type of feature for\ngggenes to draw? [Open a new issue](https://github.com/wilkox/gggenes/issues/new) \nand it will be considered.\n\n## Related packages\n\n- [gggenomes](https://thackl.github.io/gggenomes/) for visualising comparative genomics\n- [plasmapR](https://github.com/BradyAJohnston/plasmapR) for quickly drawing plasmid maps from GenBank files\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilkox%2Fgggenes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilkox%2Fgggenes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilkox%2Fgggenes/lists"}