{"id":33187102,"url":"https://friendly.github.io/ggbiplot/","last_synced_at":"2025-11-25T18:00:41.586Z","repository":{"id":138803002,"uuid":"532366080","full_name":"friendly/ggbiplot","owner":"friendly","description":"A ggplot2 based biplot for principal components-like methods","archived":false,"fork":true,"pushed_at":"2025-09-16T20:12:36.000Z","size":6915,"stargazers_count":12,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-22T03:49:11.864Z","etag":null,"topics":["biplot","data-visualization","dimension-reduction","principal-component-analysis"],"latest_commit_sha":null,"homepage":"https://friendly.github.io/ggbiplot/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"vqv/ggbiplot","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/friendly.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}},"created_at":"2022-09-03T20:22:54.000Z","updated_at":"2025-09-16T20:12:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"c9580672-227b-4820-b1ac-f26a4f44fd55","html_url":"https://github.com/friendly/ggbiplot","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/friendly/ggbiplot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendly%2Fggbiplot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendly%2Fggbiplot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendly%2Fggbiplot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendly%2Fggbiplot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/friendly","download_url":"https://codeload.github.com/friendly/ggbiplot/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendly%2Fggbiplot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286079811,"owners_count":27282121,"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","status":"online","status_checked_at":"2025-11-25T02:00:05.816Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["biplot","data-visualization","dimension-reduction","principal-component-analysis"],"created_at":"2025-11-16T05:00:30.371Z","updated_at":"2025-11-25T18:00:41.550Z","avatar_url":"https://github.com/friendly.png","language":"HTML","readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n\u003c!-- badges: start --\u003e\n[![CRAN status](https://www.r-pkg.org/badges/version/ggbiplot)](https://CRAN.R-project.org/package=ggbiplot)\n[![Last Commit](https://img.shields.io/github/last-commit/friendly/ggbiplot)](https://github.com/friendly/ggbiplot)\n[![Downloads](https://cranlogs.r-pkg.org/badges/ggbiplot)](https://cran.r-project.org/package=ggbiplot)\n\u003c!-- badges: end --\u003e\n\n\n\n\u003c!-- This repo for the **ggbiplot** package --\u003e\n\u003c!-- was forked from [https://github.com/vqv/ggbiplot](https://github.com/vqv/ggbiplot) by Vince Vu, which has been dormant --\u003e\n\u003c!-- since 2015.   --\u003e\n\u003c!-- The goal is to complete that development and publish a new version on CRAN with Vince Vu as the principal author. --\u003e\n\u003c!-- There is also an [experimental branch](https://github.com/friendly/ggbiplot/tree/experimental) which attempts to --\u003e\n\u003c!-- simplify the code, but this has some unresolved problems. --\u003e\n\n\n\n```{r, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  message = FALSE, \n  warning = FALSE,\n  comment = \"#\u003e\",\n  fig.height = 6,\n  fig.width = 6,\n  fig.path = \"man/figures/README-\"\n)\n\noptions(digits = 3)\n\n# find the current git branch\n# from: https://gist.github.com/hadley/3427128\n# kludge because find_git() not available\ngit_branch \u003c- function() {\n  # git \u003c- \"C:/Program Files/Git/bin/git.exe\"\n  git \u003c- Sys.which(\"git\")\n  system2(git, \"symbolic-ref --short -q HEAD\", stdout = TRUE, stderr = FALSE)\n}\n\n```\n\n# ggbiplot \u003cimg src=\"man/figures/logo.png\" height=\"200\" style=\"float:right; height:200px;\"/\u003e\n**Version** `r packageVersion(\"ggbiplot\")` ( `r git_branch()` branch )\n\nThis package provides a `ggplot2` implementation of the biplot, a simultaneous\nplot of scores for observations and vectors for variables for principal component-like analyses.  \nThe package provides two main functions: `ggscreeplot()` and `ggbiplot()`.\n\n`ggbiplot` aims to be a drop-in replacement for the standard R function `stats::biplot()` with extended functionality \nfor labeling groups, drawing a correlation circle, and adding data ellipsoids. \nIt also supports PCA-like objects calculated by `FactoMineR::PCA()`, `ade4::dudi.pca()` and `MASS::lda()`.\n\nThe package was originally developed by Vince Vu at [https://github.com/vqv/ggbiplot](https://github.com/vqv/ggbiplot).\nThat development was supported in part by NSF Postdoctoral Fellowship DMS-0903120 from 2009-2012.\nThe current version, now on CRAN, will be the locus of further development.\n\n\n## Installation\n\nYou can install the latest CRAN version, or install from GitHub as shown below.\n\n+-------------------+-----------------------------------------------------------------+\n| CRAN version      | `install.packages(\"ggbiplot\")`                                  |\n+-------------------+-----------------------------------------------------------------+\n| GitHub            | `remotes::install_github(\"friendly/ggbiplot\")`                  |\n| `master`          |                                                                 |\n+-------------------+-----------------------------------------------------------------+\n\n\n## Examples\n\nLoad packages:\n\n```{r}\nlibrary(ggplot2)\nlibrary(ggbiplot)\nlibrary(dplyr)\nlibrary(corrplot)\n\n# set ggplot2 theme\ntheme_set(theme_minimal(base_size = 14))\n```\n\n### Crime data\n\nThe `crime` data gives rates of various serious crimes in each of the 50 U. S. states, \noriginally from the United States Statistical Abstracts (1970).\n\nLet's take a quick look at the correlations among these, using `corrplot::corrplot()`\nand showing each correlation by an ellipse whose eccentricity and shading represents the value of\nthe correlation.\n\n```{r crime-corrplot}\ndata(crime)\ncrime |\u003e \n  dplyr::select(where(is.numeric)) |\u003e \n  cor() |\u003e \n  corrplot(method = \"ellipse\", tl.srt = 0)\n```\n\nThe correlations are all positive.  Note also that the variables in the dataset\nare ordered in seriousness or violence, ranging from murder to auto theft.\n\nCarry out a PCA:\n\n```{r crime-pca}\ncrime.pca \u003c- \n  crime |\u003e \n  dplyr::select(where(is.numeric)) |\u003e\n  prcomp(scale. = TRUE)\n\ncrime.pca\n```\n\nThe biplot, using default scaling (standardized components), and labeling the\nstates by their state abbreviation:\n\n```{r crime-biplot0}\nggbiplot(crime.pca,\n         labels = crime$st ,\n         circle = TRUE,\n         varname.size = 4,\n         varname.color = \"red\") \n```\n\nThe directions of the principal components are arbitrary; we are free to reflect\nthe variable vectors and component scores to facilitate interpretation.\nAlso, there seem to be differences among regions of the U.S., which can be\nvisualized using data ellipses for the component scores. The `groups` argument\nallows the observations to colored by group and to summarized by groups.\n \n```{r crime-biplot1}\ncrime.pca \u003c- reflect(crime.pca)\nggbiplot(crime.pca,\n         groups = crime$region,\n         labels = crime$st,\n         labels.size = 4,\n         var.factor = 1.4,\n         ellipse = TRUE, ellipse.level = 0.5, ellipse.alpha = 0.1,\n         circle = TRUE,\n         varname.size = 4,\n         varname.color = \"black\") +\n  labs(fill = \"Region\", color = \"Region\") +\n  theme(legend.direction = 'horizontal', legend.position = 'top')\n```\n\nThe interpretation of the data is now clear. \n\n* The first dimension,\naccounting for 58.8% of variance, can be seen to represent **overall\ncrime rate**, with Nevada (NV) at the high end and North Dakota (ND),\nSouth Dakota (SD) and West Virginia (WV) at the low end.\n\n* The second dimension, accounting for 17.7% of variance represents\na contrast between\n**personal crime vs. property crime**. On this dimension, Massachusetts (MA),\nRhode Island (RI) are opposed to Mississippi (MS), Alabama (AL), Louisiana (LA) and South\nCarolina (SC).\n\n* The regions are represented by the differences in the centers of the\ndata ellipses for the scores. Southern states are highest on murder,\nassault and rape, while the Northeast states are highest on auto theft\nand larceny.\n\n* In this standardized view, the angles between variable vectors approximate\nthe correlations among the variables, according to $\\cos (\\text{angle}) \\approx r$.\nThus, `murder` and `auto`, nearly $90^o$ reflect a near 0 correlation.\n\n### Wine data\n\nThe `wine` data contains results of a chemical analysis of wines grown in the same region in Italy,\nderived from three different cultivars. The analysis determined the \nquantities of 13 chemical constituents found in each of the three types of wines. \nThe grape varieties (cultivars), **barolo**, **barbera**, and **grignolino**, are given in `wine.class`.\n\nWhat can we understand about the differences among these wines from a biplot?\n\n```{r wine-screeplot}\ndata(wine)\nwine.pca \u003c- prcomp(wine, scale. = TRUE)\nggscreeplot(wine.pca) \n```\n\nHmm. The screeplot shows that more than two dimensions are necessary to account for most of the variance.\n\nPlot the first two PCA dimensions, accounting for 55% of the variance.\n```{r wine-biplot}\nggbiplot(wine.pca, \n  obs.scale = 1, var.scale = 1,\n  groups = wine.class, \n  varname.size = 4,\n  ellipse = TRUE, \n  circle = TRUE) +\n  labs(fill = \"Cultivar\", color = \"Cultivar\") +\n  theme(legend.direction = 'horizontal', legend.position = 'top')\n```\n\nThe three cultivars are arranged along the first dimension, in the order barolo \u003c grignolino \u003c barbera.\nThese are distinguished largely by a contrast between (`Phenols`, `Flav`) vs. (`NonFlavPhenols`, `AlcAsh`).\nThe second dimension is represented by the cluster of variables `Mg`, `Alcohol`, `Ash`, `Color`, which distinguishes\ngrignolino from the other two.\n\n### Iris data\n\nThe classic iris data is widely used for examples of multivariate analysis and biplots, so let's use it here.\n\n```{r iris-pca}\ndata(iris)\niris.pca \u003c- prcomp (~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width,\n                    data=iris,\n                    scale. = TRUE)\nsummary(iris.pca)\n```\n\nPlot the first two dimensions:\n\n```{r iris-biplot0}\niris.gg \u003c-\nggbiplot(iris.pca, obs.scale = 1, var.scale = 1,\n         groups = iris$Species, point.size=2,\n         varname.size = 5, \n         varname.color = \"black\",\n         varname.adjust = 1.2,\n         ellipse = TRUE, \n         circle = TRUE) +\n  labs(fill = \"Species\", color = \"Species\") +\n  theme_minimal(base_size = 14) +\n  theme(legend.direction = 'horizontal', legend.position = 'top')\n\niris.gg\n```\n\nIt is possible to add annotations to the biplot by making use of the fact that `ggplot()` returns a lot of\ninformation in the `\"gg\"` object. In particular, the `$data` component contains the scores on the principal\ncomponents that are plotted as points here.\nHere we add direct labels for the groups and suppress the legend.\n\n```{r iris-labs}\n# get means of coordinates by group\ngroup.labs \u003c-\n  iris.gg$data |\u003e\n  summarise(xvar = mean(xvar),\n            yvar = mean(yvar), .by = groups)\n\ngroup.labs\n```\n\nNow, just use `geom_label` to draw labels for the groups.\n```{r iris-biplot1}\niris.gg + geom_label(data = group.labs,\n                     aes(x = xvar, y=yvar, label=groups),\n                     size = 5) +\n  theme(legend.position = \"none\")\n```\n\n\n\n","funding_links":[],"categories":["Data and models"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/friendly.github.io%2Fggbiplot%2F","html_url":"https://awesome.ecosyste.ms/projects/friendly.github.io%2Fggbiplot%2F","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/friendly.github.io%2Fggbiplot%2F/lists"}