{"id":32200452,"url":"https://github.com/xuan-liang/ggmatplot","last_synced_at":"2026-02-21T03:32:21.044Z","repository":{"id":56934244,"uuid":"195039918","full_name":"xuan-liang/ggmatplot","owner":"xuan-liang","description":"An R package for plotting wide-format data","archived":false,"fork":false,"pushed_at":"2025-01-16T23:40:50.000Z","size":34342,"stargazers_count":5,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-12-09T17:38:47.551Z","etag":null,"topics":["data-visualization","r-package"],"latest_commit_sha":null,"homepage":"https://xuan-liang.github.io/ggmatplot/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xuan-liang.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-07-03T11:25:11.000Z","updated_at":"2025-01-16T23:39:22.000Z","dependencies_parsed_at":"2024-05-06T03:24:24.732Z","dependency_job_id":"3840df72-0766-4549-8f92-d594153fa973","html_url":"https://github.com/xuan-liang/ggmatplot","commit_stats":{"total_commits":199,"total_committers":6,"mean_commits":"33.166666666666664","dds":0.5477386934673367,"last_synced_commit":"ef95fd440e7589e5893561d6b593931789744941"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/xuan-liang/ggmatplot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuan-liang%2Fggmatplot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuan-liang%2Fggmatplot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuan-liang%2Fggmatplot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuan-liang%2Fggmatplot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xuan-liang","download_url":"https://codeload.github.com/xuan-liang/ggmatplot/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuan-liang%2Fggmatplot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29672704,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T03:11:15.450Z","status":"ssl_error","status_checked_at":"2026-02-21T03:10:34.920Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["data-visualization","r-package"],"created_at":"2025-10-22T03:48:28.295Z","updated_at":"2026-02-21T03:32:21.020Z","avatar_url":"https://github.com/xuan-liang.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"80%\",\n  message = FALSE,\n  warning = FALSE\n)\n```\n\n[![DOI](https://zenodo.org/badge/195039918.svg)](https://zenodo.org/badge/latestdoi/195039918)\n\n\n# ggmatplot\n\n`ggmatplot` is a quick and easy way of plotting the columns of two matrices or \ndata frames against each other using [`ggplot2`](https://ggplot2.tidyverse.org/).\n\n## Overview\n\n[`ggplot2`](https://ggplot2.tidyverse.org/) requires wide format data to be \nwrangled into long format for plotting, which can be quite cumbersome when \ncreating simple plots. Therefore, the motivation for `ggmatplot` is to provide \na solution that allows [`ggplot2`](https://ggplot2.tidyverse.org/) to handle \nwide format data. Although `ggmatplot` doesn't provide the same flexibility \nas [`ggplot2`](https://ggplot2.tidyverse.org/), it can be used as a \nworkaround for having to wrangle wide format data into long format and creating\nsimple plots using [`ggplot2`](https://ggplot2.tidyverse.org/).\n\n`ggmatplot` is built upon [`ggplot2`](https://ggplot2.tidyverse.org/), and its \nfunctionality is inspired by \n[`matplot`](https://www.rdocumentation.org/packages/graphics/versions/3.6.2/topics/matplot).\nTherefore, `ggmatplot` can be considered as a `ggplot` version of \n[`matplot`](https://www.rdocumentation.org/packages/graphics/versions/3.6.2/topics/matplot).\n\nSimilar to [`matplot`](https://www.rdocumentation.org/packages/graphics/versions/3.6.2/topics/matplot),\n`ggmatplot` plots a vector against the columns of a matrix, or the columns of \ntwo matrices against each other, or a vector/matrix on its own. However, unlike\n[`matplot`](https://www.rdocumentation.org/packages/graphics/versions/3.6.2/topics/matplot),\n`ggmatplot` returns a `ggplot` object. Therefore, \n[ggplot add ons](https://ggplot2.tidyverse.org/reference/index.html) such as \nscales, faceting specifications, coordinate systems and themes can also be added\non to the resultant `ggplot` object.\n\n## Installation\n\nThe latest version can be installed from [CRAN](https://CRAN.R-project.org/package=ggmatplot):\n\n```{r eval=FALSE}\ninstall.packages(\"ggmatplot\")\n```\n\nOr you can install the development version from [GitHub](https://github.com/xuan-liang/ggmatplot):\n\n```{r eval=FALSE}\n# install.packages(\"devtools\")\ndevtools::install_github(\"xuan-liang/ggmatplot\")\n```\n\n## Examples\n\n```{r}\nlibrary(ggmatplot)\n```\n\nThe first example plots a vector against each column of matrix using the default `plot_type = \"point\"` of `ggmatplot()`. We consider a simple case that we have a covariate vector `x` and a matrix `z` with the response `y` and the fitted value `fit.y` as the two columns.    \n\n```{r point}\n# vector x\nx \u003c- c(rnorm(100, sd = 2))\n\n# matrix z\ny \u003c- x * 0.5 + rnorm(100, sd = 1)\nfit.y \u003c- fitted(lm(y ~ x))\nz \u003c- cbind(\n  actual = y,\n  fitted = fit.y\n)\n\nggmatplot(x, z)\n```\n\nIf two matrices with equal number of columns are used, the corresponding columns of the matrices will be plotted against each other, i.e. column 1 of matrix `y` will be plotted against column 1 of matrix `x`, column 2 of matrix `y` will be plotted against column 2 of matrix `x`, etc.\n\nThe next example uses the iris dataset, with matrices `x` and `y` as shown below. The `Sepal.Width` is plotted against `Sepal.Length` and the `Petal.Width` is plotted against `Petal.Length`. Therefore the groups 'Column 1' and 'Column 2' can be interpreted as 'Sepal' and 'Petal' respectively. To make the plot more meaningful, we can further modify the legend label and axis names by `legend_label`, `xlab` and `ylab`.\n\n```{r point-columns}\nx \u003c- (iris[, c(1, 3)])\nhead(x, 5)\n\ny \u003c- (iris[, c(2, 4)])\nhead(y, 5)\n\nggmatplot(x, y)\nggmatplot(x, y,\n  xlab = \"Length\",\n  ylab = \"Width\",\n  legend_label = c(\"Sepal\", \"Petal\")\n)\n```\n\n\nThe next example creates a line plot of vector `x` against the columns of matrix `y` by using `plot_type = \"line\"`. Although the lines would be represented using different colors by default, the `color` parameter allows custom colors to be assigned to them.  \n\nThe following plot assigns custom colors to the lines, and the limits of the y axis are updated using the `ylim` parameter. Further, a ggplot theme is added on to the resultant ggplot object.\n\n```{r line}\n# matrix x\nx \u003c- 1:10\n\n# matrix y\ny \u003c- cbind(\n  square = x^2,\n  cube = x^3\n)\n\nggmatplot(x, y,\n  plot_type = \"line\",\n  color = c(\"blue\", \"purple\"),\n  ylim = c(0, 750)\n) +\n  theme_minimal()\n```\n\nNext is the plot of the US personal expenditure over 5 categories and 5 years, and is a simple example of how wide format data can be used with `ggmatplot()`. Note how the expenditure categories to be used on the x axis is used as vector `x`, and the expenditure values is used in wide format as matrix `y` - with its columns corresponding to the grouping structure.\n\nThe plot specifies the plot type as `plot_type = \"both\"`, which is a combination of 'point' and 'line' plots. It is further customized by using `ggmatplot()` parameters and a `ggplot` theme as well.\n\n\n```{r both}\nUSPersonalExpenditure\n\n# vector x\nx \u003c- rownames(USPersonalExpenditure)\n\nggmatplot(x, USPersonalExpenditure,\n  plot_type = \"both\",\n  xlab = \"Category\",\n  ylab = \"Expenditure (in Billions of Dollars)\",\n  legend_title = \"Year\",\n  legend_label = c(1940, 1945, 1950, 1955, 1960)\n) +\n  theme(axis.text.x = element_text(angle = 45, hjust = 1))\n```\n\nDensity plots only accept a single matrix or data frame and will group the plot based on its columns. The following density plot uses a two column matrix, and groups the plot by the two columns. While the default density estimate is represented in the measurement units of the data, an aesthetic mapping is added on to the ggplot object to scale the density estimate to a maximum of 1.\n\n```{r density}\n# matrix x\nx \u003c- (iris[, 1:2])\n\nggmatplot(x, plot_type = \"density\") +\n  aes(y = stat(scaled)) +\n  theme_bw()\n```\n\nBoxplots accept only a single matrix or data frame as well, and uses its columns as individual groups. By default, the fill color is white. But it is easy to customize and the transparency can be modified by the `alpha` parameter.\n\nIt is also worth noticing that `alpha` isn't a parameter defined in `ggmatplot()`, but can be used. This is because `ggmatplot` is built upon `ggplot2`, and each `plot_type` corresponds to a [`geom`](https://ggplot2.tidyverse.org/reference/index.html#section-geoms) as listed [here](https://xuan-liang.github.io/ggmatplot/reference/ggmatplot.html#plot-types). Therefore, all valid parameters with the underlying [`ggplot2 geom`](https://ggplot2.tidyverse.org/reference/index.html#section-geoms) can be used with `ggmatplot()`.\n\n```{r boxplot}\n# matrix x\nx \u003c- (iris[, 1:4])\n\nggmatplot(x,\n  plot_type = \"boxplot\",\n  color = 'black', \n  fill = 'grey',\n  alpha = 0.8,\n  xlab = \"\", ylab = \"\"\n)\n```\n\nViolin plots accept a single matrix or data frame input, and behave similar to density plots and boxplots.\n\nThis plot updates the colors of the two groups using the `color` parameter, and it can be seen that the fill of the violin plots has been updated too. This is because updating either the `color` or `fill` parameter will automatically update the other, unless they are both defined simultaneously.\n\n\n```{r violin}\n# matrix x\nx \u003c- (iris[, 1:2])\n\nggmatplot(x,\n  plot_type = \"violin\",\n  color = c(\"#00AFBB\", \"#E7B800\"),\n  xlab = \"\", ylab = \"\"\n)\n```\n\nDotplots too accept a single matrix input and plot the distribution of each of its columns. The next example uses the `plot_type = \"dotplot\"` to visualize the distribution of the data with the custom color and binwidth value. Note that the default setting for binwidth is 1/30 of the range of the data.\n\n```{r dotplot}\n# matrix x\nx \u003c- (iris[, 1:2])\n\nggmatplot(x,\n  plot_type = \"dotplot\",\n  color = c(\"#00AFBB\", \"#E7B800\"),\n  binwidth = 0.1,\n  xlab = \"\", ylab = \"\"\n)\n```\n\nSimilar to density, violin, dotplots, and box plots, histograms too accept a single matrix or data frame input and group the plot using its columns. The histogram in the following example uses a matrix of 4 columns, and therefore groups the plots based on these 4 columns. The plot is also faceted by group and the legend is removed by a `ggplot` theme setting.\n\nThe `color` and `fill` parameters have been defined simultaneously on this plot. However, only a single `color` value is defined whereas the number of `fill` colors correspond to the number of groups. If a single value is defined it will be used over all groups, like the black line color is used across all groups in this example.\n\n```{r histogram}\n# matrix x\nx \u003c- (iris[, 1:4])\n\nggmatplot(x,\n  plot_type = \"histogram\",\n  xlab = \"\",\n  color = \"black\",\n  fill = c(\"#F8766D\", \"#7CAE00\", \"#00BFC4\", \"#C77CFF\")\n) +\n  facet_wrap(~Group, scales = \"free\") + \n  theme(legend.position = 'none')\n```\n\nThe next example is of the `plot_type = ecdf`, and also uses a single matrix input to plot out the empirical cumulative distributions of the columns of the matrix individually.\n\n```{r ecdf}\n# matrix x\nx \u003c- (iris[, 1:4])\n\nggmatplot(x,\n  plot_type = \"ecdf\",\n  xlab = \"\",\n  ylab = 'Empirical CDF',\n  size = 1\n) +\n  theme_minimal()\n```\n\nError plots also accept only a single matrix input, and plots out error bars for each column of the matrix. The `desc_stat` parameter of `ggmatplot()` can be used to define what the mid point and error bars of the plot should represent.\n\nThe next example, plots out an `errorplot` using the medians and interquartile ranges of each variable.\n\n```{r errorplot}\n# matrix x\nx \u003c- (iris[, 1:4])\n\nggmatplot(x,\n  plot_type = \"errorplot\",\n  desc_stat = \"median_iqr\",\n  xlab = \"\",\n  size = 1\n) +\n  theme_minimal()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxuan-liang%2Fggmatplot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxuan-liang%2Fggmatplot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxuan-liang%2Fggmatplot/lists"}