{"id":20431936,"url":"https://github.com/cxli233/ggtraces","last_synced_at":"2025-04-12T20:52:02.882Z","repository":{"id":48349837,"uuid":"516867891","full_name":"cxli233/ggtraces","owner":"cxli233","description":"A tidyverse and grammar of graphics powered line traces visualizer ","archived":false,"fork":false,"pushed_at":"2024-07-11T01:59:14.000Z","size":348,"stargazers_count":28,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-12T20:51:53.151Z","etag":null,"topics":["chromatogram-traces","data-visualization","line-traces","r"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cxli233.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null}},"created_at":"2022-07-22T19:40:01.000Z","updated_at":"2025-01-20T06:26:32.000Z","dependencies_parsed_at":"2024-11-15T08:13:29.346Z","dependency_job_id":"6d887d36-2ce9-4a44-974f-d9855f753ad9","html_url":"https://github.com/cxli233/ggtraces","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxli233%2Fggtraces","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxli233%2Fggtraces/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxli233%2Fggtraces/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxli233%2Fggtraces/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cxli233","download_url":"https://codeload.github.com/cxli233/ggtraces/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631728,"owners_count":21136560,"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":["chromatogram-traces","data-visualization","line-traces","r"],"created_at":"2024-11-15T08:13:25.979Z","updated_at":"2025-04-12T20:52:02.849Z","avatar_url":"https://github.com/cxli233.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# ggtraces - A tidyverse and grammar of graphics powered line traces visualizer  \n\nv.1.0.0 release: \n[![DOI](https://zenodo.org/badge/516867891.svg)](https://zenodo.org/badge/latestdoi/516867891)\n\n\nAuthor: Chenxin Li, Ph.D., Assistant Research Scientist at Department of Crop \u0026 Soil Sciences and Center for Applied Genetic Technologies, University of Georgia. \n\n  Contact: [Chenxin.Li@uga.edu](Chenxin.Li@uga.edu)\n\nThe main goal of this repository is to empower R users such that we can produce publication quality chromatograms with R. \nExamples and explanations are below. \n\nThe `Scripts/` directory contains `.Rmd` files that generate the graphics shown below. \nIt requires R, RStudio, and the rmarkdown package. \n\n* R: [R Download](https://cran.r-project.org/bin/)\n* RStudio: [RStudio Download](https://www.rstudio.com/products/rstudio/download/)\n* rmarkdown can be installed using the intall packages interface in RStudio\n\n# Table of contents \n\n1. [Dependencies](https://github.com/cxli233/ggtraces#dependencies)\n2. [Required input](https://github.com/cxli233/ggtraces#required-input)\n3. [Functions generated by the workflow](https://github.com/cxli233/ggtraces#functions-defined-by-the-workflow)\n4. [Example output](https://github.com/cxli233/ggtraces#example-output)\n5. [Real datasets](https://github.com/cxli233/ggtraces#real-datasets)\n    - [LC-MS example](https://github.com/cxli233/ggtraces#lc-ms-data)\n    - [Metagene example](https://github.com/cxli233/ggtraces#metagene-data)\n6. [Getting started](https://github.com/cxli233/ggtraces#getting-started) \n7. [Example script](https://github.com/cxli233/ggtraces#example-script)\n    - [Load data](https://github.com/cxli233/ggtraces#load-data)\n    - [Rename columns](https://github.com/cxli233/ggtraces#rename-columns)\n    - [Run ggtraces functions](https://github.com/cxli233/ggtraces#run-ggtrace-functions-one-by-one)\n    - [Final touches](https://github.com/cxli233/ggtraces#final-touches)\n8. [Comparison of perspectives](https://github.com/cxli233/ggtraces#comparison-of-perspectives) \n9. [Additional features](https://github.com/cxli233/ggtraces#additional-features)\n    - [Facet plot](https://github.com/cxli233/ggtraces#facet-plot)\n    - [Pherogram](https://github.com/cxli233/ggtraces#pherogram)\n   \n\n# Dependencies\n```{r}\nlibrary(tidyverse)\n```\nThis is a tidyverse based workflow.\n\n# Required input\nThe workflow requires the input data to be in the tidy format (each row is an observation, and each column is a variable).\n\nIt requires the following 3 columns: \n\n1. The column named `x`, which will be the x axis \n2. the column named `y`, which will be the y axis\n3. A `sample` column that indicates the sample ID of each of the traces. \n\nAddition required values:\n\n1. a vector of sample IDs \n2. x_offset, default = 0.2\n3. y_offset, default = 0.4\n4. number of traces to plot \n\n# Functions defined by the workflow\nThis workflow defines a 6 functions in this order:\n\n1. `find_xy_ranges()` takes the tidy input data frame and finds xmin, xmax, ymin, and ymax. \n2. `make_grid_table()` takes the ranges produced by `find_xy_ranges()` and produce a data frame that will be used to make the coordinate system. Additionally, it requires `x_offset` and `y_offset` and `number_of_traces`. \n3. `make_axis_table()` takes the ranges produced by `find_xy_ranges()` and produce a data frame that will be used to make the coordinate system.\n4. `make_coord()` takes the output of `find_xy_ranges()`, `make_grid_table()`, `make_axis_table`, to make a ggplot object that is a blank coordinate system. It also requires `x_offset` and `y_offset` and `number_of_traces`.\n5. `map_sample_to_trace()` takes a vector of sample IDs and produce a data frame that maps sample IDs to traces (column of 1 to n). \n6. `plot_traces()` takes the output of all the above and produce a ggplot object. \n\n# Example output\nAs a example, let's visualize two sine waves. \n\nThe workflow first generates a blank coordinate system, which is a ggplot object (a \"grob\").\n\n* The coordinate system is definbed by x and y value ranges, as well as number of traces to graph. \n* The perspective of the coordinate system is defined by `x_offset` and `y_offset`.  \n\n![Example blank coord](https://github.com/cxli233/ggtraces/blob/main/Results/blank_coord.svg) \n\nAgain, the blank coordinate is a \"grob\" object. \nWe can add ggplot layers to, such as geom, scale, theme, and so on. \n\nThe trace plot in its most basic form, is the blank coordinate system + `geom_line()` to plot the line traces. \n\n![Example trace plot](https://github.com/cxli233/ggtraces/blob/main/Results/example_1.svg)\n\nThis is showing two sine ways aligned along a parallelogram. \nThis is a grob object. \nWe can add more ggplot layers to it if needed, such as replacing the default color palette. \nUsually it requires some final touches to make it look nicer. \n\n![Example trace plot, but nicer](https://github.com/cxli233/ggtraces/blob/main/Results/example_1_nicer.svg)\n\n# Real datasets \nThe best way to use this tool is running `ggtraces.Rmd` in the same environment (same RStudio window) in a different tab. \nDoing so will deposite the functions needed into the environment. \nThen you can simply call the functions one-by-one. \n\nI tried out two real datasets that are very different. \nThe first one is LC-MS data. \nData from [Li et al., 2022](https://www.biorxiv.org/content/10.1101/2022.07.04.498697v1)  \nThe second one is small RNA metagene (averaged gene) data. \nData from [Li et al., 2020](https://genome.cshlp.org/content/30/2/173.short) and [Li et al., 2022](https://genome.cshlp.org/content/32/2/309.short).\n\nRunning `ggtraces_uses.Rmd` in the `Scripts/` directory will generate these graphs. \n\n## LC-MS data \n![LC-MS example](https://github.com/cxli233/ggtraces/blob/main/Results/LC_MS_example.svg)\nThis is showing the base peak chromatograms (normalized to higest peak) of two samples. \n\n## Metagene data\n![Metagene example](https://github.com/cxli233/ggtraces/blob/main/Results/metagene_example.svg)\nThis is showing normalized coverage of 24-nt siRNAs (per 1000 24-nt siRNAs) arround transcription start sites, averaged across all genes.\n\n# Getting started\n\n1. Clone the repository to your machine.\n2. Run `ggtraces.Rmd` under `Scripts/`. You will need to install the rmarkdown package. \n3. Call each function in order.\n4. Make final touches (e.g., adjust axis range, axis label, color palette, and so on)\n5. Done! \n\n# Example script\n## Load data\n```{r}\nmetagene \u003c- read_csv(\"../Data/metagene.csv\", col_types = cols())\n```\nThis is already a tidy data frame. \nIf your data table is not in the tidy format, you'll need to re-format it first. \n\n## Rename columns \n```{r}\nmetagene_2 \u003c- metagene %\u003e% \n  dplyr::rename(x = `bin start`,\n                sample = sample_type) %\u003e% \n  mutate(y = mena_pro_24 * 1000)\n```\n\nThe workflow requires `x`, `y`, and `sample` columns. \n\n## Run ggtrace functions one by one\n```{r}\nexample3_ranges \u003c- find_xy_ranges(metagene_2)\nexample3_grid_table \u003c- make_grid_table(example3_ranges, x_offset = 200, y_offset = 150, number_traces = 5)\nexample3_axis_table \u003c- make_axis_table(example3_ranges)\n\nexample3_coord \u003c- make_coord(\n  grid_table = example3_grid_table, \n  axis_table = example3_axis_table,\n  ranges = example3_ranges,\n  number_traces = 5,\n  x_offset = 200,\n  y_offset = 150\n)\n\nexample3_names \u003c- c(\"sperm\", \"egg\", \"zygote\", \"seedling\")\nexample3_mapping \u003c- map_sample_to_trace(example3_names)\n\nexample3_traces \u003c- plot_traces(\n  data = metagene_2,\n  coord = example3_coord,\n  mapping = example3_mapping,\n  x_offset = 200,\n  y_offset = 150,\n  ranges = example3_ranges,\n  x_title = \"Position relative to TSS\",\n  y_title = \"Normalized\\ncoverage\",\n  sample_ID_title = \"Cell type\"\n)\n```\n* You will need to provide `x_offset`, `y_offset`, and `number_of_traces`. These values differ across experiments.\n* You will need to provide the names of the traces. They are prodived via `example3_names \u003c- c(\"sperm\", \"egg\", \"zygote\", \"seedling\")`.\n\n## Final touches \nManually adjust axis breaks, axis range, color palette, and axis title position.\nSince `example3_traces` is a ggplot object, we can easily make additional customizations.  \n\n```{r}\nexample3_traces +\n  geom_segment(x = -Inf, xend = -Inf, y = 0, yend = 800, size = 1.1, color = \"grey20\") +\n  geom_segment(x = -3000, xend = 2000, y = -Inf, yend = -Inf, size = 1.1, color = \"grey20\") +\n  scale_color_manual(values = c(\"dodgerblue2\", \"tomato1\", \"violetred4\", \"seagreen\"),\n                     limits = example3_mapping$sample) +\n  scale_y_continuous(breaks = c(0, 200, 400, 600, 800)) +\n  theme(legend.position = \"top\",\n        axis.title.y = element_text(hjust = 0.4))\n```\n![Metagene example](https://github.com/cxli233/ggtraces/blob/main/Results/metagene_example.svg)\nDone! \n\n# Comparison of perspectives\nDifferent `x_offset` and `y_offset` values changes the apparence of the final product. \n![LC MS different perspectives](https://github.com/cxli233/ggtraces/blob/main/Results/LC_MS_perspectives.svg) \n\n* High x_offset and low y_offset facilitate comparisons along y axis. It gives the sensation that we are looking at the graph from the side.\n* Low x_offset and high y_offset facilitate comparisons along x axis. It gives the sensation that we are looking at the graph from the top.\n\n# Additional features\n## Facet plot\nFacet plot is a plot type where each line trace gets its own x and y axis.\n\n```{r}\nplot_facet(LC_MS_data_2, x_title = \"Retention time (min)\", y_title = \"Relative intensity\") +\n  scale_color_manual(values = brewer.pal(8, \"Set2\")[c(1,4)]) \n```\n![LC MS facet plot](https://github.com/cxli233/ggtraces/blob/main/Results/LC_MS_facet.svg)\n\nThe `plot_facet()` function requires the tidy data frame as input. `x_title` and `y_title` are optional. \nDefaults are \"x\" and \"y\", respectively. \n\n## Pherogram \nPherogram is short for electropherogram, where we imagine the traces are moving down a gel.\nThe original y value is now represented as color intensity in the heat map. \n\n```{r}\nplot_pherogram(data = metagene_2, \n               y_title = \"Position relative to TSS\", \n               legend_title = \"Normalized\\ncoverage\",\n               mapping = example3_mapping)\n```\n![Metagene pherogram](https://github.com/cxli233/ggtraces/blob/main/Results/metagene_pherogram.svg)\n\nThe `plot_pherogram()` function requires the tidy data frame as input. \n`y_title` argument controls the y axis title (default = \"x\"), since it was the x value in the original line traces.\n`legend_title` argument controls the title of the color scale (default = \"y\"), since it was the y value in the origal line traces. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcxli233%2Fggtraces","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcxli233%2Fggtraces","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcxli233%2Fggtraces/lists"}