{"id":14066676,"url":"https://github.com/LudvigOlsen/rearrr","last_synced_at":"2025-07-29T23:31:58.418Z","repository":{"id":56934593,"uuid":"259158437","full_name":"LudvigOlsen/rearrr","owner":"LudvigOlsen","description":"Rearrrange data by a set of methods","archived":false,"fork":false,"pushed_at":"2025-03-06T18:28:48.000Z","size":13724,"stargazers_count":23,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-28T13:46:42.861Z","etag":null,"topics":["arrange","cluster","expand","forming","generate","ggplot2","order","plotting-in-r","roll","rotate","shaping","swirl","transformations"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LudvigOlsen.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":".github/SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-26T23:50:56.000Z","updated_at":"2025-05-20T20:10:14.000Z","dependencies_parsed_at":"2024-08-13T07:11:23.064Z","dependency_job_id":"382daab6-f2b9-485e-a70a-e8a9f8e596dc","html_url":"https://github.com/LudvigOlsen/rearrr","commit_stats":{"total_commits":214,"total_committers":3,"mean_commits":71.33333333333333,"dds":"0.12149532710280375","last_synced_commit":"40d150b440ae06507873fad20a28345c08d48cf3"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/LudvigOlsen/rearrr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LudvigOlsen%2Frearrr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LudvigOlsen%2Frearrr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LudvigOlsen%2Frearrr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LudvigOlsen%2Frearrr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LudvigOlsen","download_url":"https://codeload.github.com/LudvigOlsen/rearrr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LudvigOlsen%2Frearrr/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267780010,"owners_count":24143201,"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-07-29T02:00:12.549Z","response_time":2574,"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":["arrange","cluster","expand","forming","generate","ggplot2","order","plotting-in-r","roll","rotate","shaping","swirl","transformations"],"created_at":"2024-08-13T07:05:12.789Z","updated_at":"2025-07-29T23:31:58.400Z","avatar_url":"https://github.com/LudvigOlsen.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, echo = FALSE, message=FALSE, warning=FALSE}\nif (requireNamespace(\"knitr\", quietly = TRUE)){\n  knitr::opts_chunk$set(\n    collapse = TRUE,\n    comment = \"#\u003e\",\n    fig.path = \"man/figures/README-\",\n    dpi = 92,\n    fig.retina = 2\n  )\n}\n\n# Get minimum R requirement \ndep \u003c- as.vector(read.dcf('DESCRIPTION')[, 'Depends'])\nrvers \u003c- substring(dep, 7, nchar(dep)-1)\n# m \u003c- regexpr('R *\\\\\\\\(\u003e= \\\\\\\\d+.\\\\\\\\d+.\\\\\\\\d+\\\\\\\\)', dep)\n# rm \u003c- regmatches(dep, m)\n# rvers \u003c- gsub('.*(\\\\\\\\d+.\\\\\\\\d+.\\\\\\\\d+).*', '\\\\\\\\1', dep)\n\n# Function for TOC\n# https://gist.github.com/gadenbuie/c83e078bf8c81b035e32c3fc0cf04ee8\n\n\n```\n\u003c!-- # rearrr \u003ca href='https://github.com/LudvigOlsen/rearrr'\u003e\u003cimg src='man/figures/rearrr_logo_242x280_250dpi.png' align=\"right\" height=\"140\" /\u003e\u003c/a\u003e --\u003e\n# rearrr\n**Rearrrange Data**  \n**Authors:** [Ludvig R. Olsen](https://www.ludvigolsen.dk/) ( r-pkgs@ludvigolsen.dk ) \n\u003ca href='https://twitter.com/ludvigolsen'\u003e\u003cimg src='man/figures/icons8-twitter.svg' height=\"17\" /\u003e\u003c/a\u003e\u003cbr/\u003e\n**License:** [MIT](https://opensource.org/license/mit) \u003cbr/\u003e\n**Started:** April 2020  \n\n[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/rearrr)](https://cran.r-project.org/package=rearrr)\n[![metacran downloads](https://cranlogs.r-pkg.org/badges/rearrr)](https://cran.r-project.org/package=rearrr)\n[![minimal R version](https://img.shields.io/badge/R%3E%3D-`r rvers`-6666ff.svg)](https://cran.r-project.org/)\n[![Codecov test coverage](https://codecov.io/gh/ludvigolsen/rearrr/branch/master/graph/badge.svg)](https://app.codecov.io/gh/ludvigolsen/rearrr?branch=master)\n[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/LudvigOlsen/rearrr?branch=master\u0026svg=true)](https://ci.appveyor.com/project/LudvigOlsen/rearrr)\n[![DOI](https://zenodo.org/badge/259158437.svg)](https://zenodo.org/badge/latestdoi/259158437)\n\n\n## Overview\n\nR package for rearranging data by a set of methods.\n\nWe distinguish between **rearrangers** and **mutators**, where the first *reorders* the data points and the second *changes the values* of the data points. \n\nWhen performing an operation relative to a point in an n-dimensional vector space, we refer to the point as the **origin**. If we, for instance, wish to rotate our data points around the point at `x = 3` and `y = 7`, those are the coordinates of our origin.\n\n\u003c/br\u003e\n\u003cdiv style=\"width: 100%; text-align: center; display: block;\"\u003e\n\u003cimg src='https://raw.githubusercontent.com/LudvigOlsen/readme_plots/master/rearrr_plots/rearrange_example_optimized.gif' width=\"338\" style=\"padding-bottom:28px !important; padding-right:28px !important;\" /\u003e\n\n\u003cimg src='https://raw.githubusercontent.com/LudvigOlsen/readme_plots/master/rearrr_plots/swirl3d_example_optimized.gif' width=\"338\" style=\"padding-bottom:28px !important;\" /\u003e\n\u003c/div\u003e\n\u003cdiv style=\"width: 100%; text-align: center; display: block;\"\u003e\n\u003cimg src='https://raw.githubusercontent.com/LudvigOlsen/readme_plots/master/rearrr_plots/formers_example_optimized.gif' width=\"338\" style=\"padding-bottom:28px !important; padding-right:28px !important;\" /\u003e\n\n\u003cimg src='https://raw.githubusercontent.com/LudvigOlsen/readme_plots/master/rearrr_plots/functions_example_optimized.gif' width=\"338\" style=\"padding-bottom:28px !important;\" /\u003e\n\u003c/div\u003e\n\n### Install\n\nCRAN (when available):\n\n\u003e `install.packages(\"rearrr\")`\n\nDevelopment version:  \n\n\u003e `install.packages(\"devtools\")`  \n\u003e\n\u003e `devtools::install_github(\"LudvigOlsen/rearrr\")`  \n\n\u003c!-- ## Vignettes   --\u003e\n\n\u003c!-- `rearrr` contains a number of vignettes with relevant use cases and descriptions:   --\u003e\n\n\u003c!-- \u003e `vignette(package = \"rearrr\")` # for an overview    --\u003e\n\n\n### Rearrangers\n\n| Function              | Description                                                           |\n|:----------------------|:----------------------------------------------------------------------|\n|`center_max()`         |Center the highest value with values decreasing around it.             |\n|`center_min()`         |Center the lowest value with values increasing around it.              |\n|`position_max()`       |Position the highest value with values decreasing around it.           |\n|`position_min()`       |Position the lowest value with values increasing around it.            |\n|`pair_extremes()`      |Arrange as lowest, highest, 2nd lowest, 2nd highest, etc.              |\n|`triplet_extremes()`   |Arrange as lowest, most middle, highest, 2nd lowest, 2nd most middle, 2nd highest, etc. |\n|`closest_to()`         |Order values by shortest distance to an origin.                        |\n|`furthest_from()`      |Order values by longest distance to an origin.                         |\n|`rev_windows()`        |Reverse order window-wise.                                             |\n|`roll_elements()`      |Rolls/shifts positions of elements.                                    |\n|`shuffle_hierarchy()`  |Shuffle multi-column hierarchy of groups.                              |\n\n### Mutators\n\n| Function              | Description                                                           | Dimensions |\n|:----------------------|:----------------------------------------------------------------------|:-----------|\n|`rotate_2d()`, `rotate_3d()` |Rotate values around an origin in 2 or 3 dimensions.             |2 or 3      |\n|`swirl_2d()`, `swirl_3d()`   |Swirl values around an origin in 2 or 3 dimensions.              |2 or 3      |\n|`shear_2d()`, `shear_3d()`   |Shear values around an origin in 2 or 3 dimensions.              |2 or 3      |\n|`expand_distances()`   |Expand distances to an origin.                                         |n           |\n|`expand_distances_each()`|Expand distances to an origin separately for each dimension.         |n           |\n|`cluster_groups()`     |Move data points into clusters around group centroids.                 |n           |\n|`dim_values()`         |Dim values of a dimension by the distance to an n-dimensional origin.  |n (alters 1)|\n|`flip_values()`        |Flip the values around an origin.                                      |n           |\n|`roll_values()`        |Shifts values and wraps to a range.                                    |n           |\n|`wrap_to_range()`      |Wraps values to a range.                                               |n           |\n|`transfer_centroids()` |Transfer centroids from one `data.frame` to another.                   |n           |\n|`apply_transformation_matrix()` |Apply transformation `matrix` to `data.frame` columns.        |n           |\n\n### Formers\n\n| Function          | Description                                                           |\n|:------------------|:----------------------------------------------------------------------|\n|`circularize()`    |Create x-coordinates for y-coordinates so they form a circle.          |\n|`hexagonalize()`   |Create x-coordinates for y-coordinates so they form a hexagon.         |\n|`square()`         |Create x-coordinates for y-coordinates so they form a square.          |\n|`triangularize()`  |Create x-coordinates for y-coordinates so they form a triangle.        |\n\n### Pipelines\n\n| Class                | Description                                                             |\n|:---------------------|:------------------------------------------------------------------------|\n|`Pipeline`            |Chain multiple transformations.                                          |\n|`GeneratedPipeline`   |Chain multiple transformations and generate argument values per group.   |\n|`FixedGroupsPipeline` |Chain multiple transformations with different argument values per group. |\n\n### Generators\n\n| Function              | Description                                                           |\n|:----------------------|:----------------------------------------------------------------------|\n|`generate_clusters()`  |Generate n-dimensional clusters.                                       |\n\nAdditionally, some functions have `*_vec()` versions, that take and return a `vector`.\n\n**Note**: The available utility functions (like scalers, converters and measuring functions) are\nlisted at the bottom of the readme.\n\n\n## Table of Contents\n\n```{r toc, echo=FALSE}\nrearrr:::render_toc(\"README.Rmd\", toc_depth = 4)\n```\n\n\n## Attach packages\n\nLet's see some **examples**. We start by attaching the necessary packages:\n\n```{r warning=FALSE, message=FALSE}\nlibrary(rearrr)\nlibrary(dplyr)\n\nxpectr::set_test_seed(1)\n```\n\n```{r include=FALSE}\nlibrary(knitr)        # kable()\nhas_tidyr \u003c- require(tidyr)        # gather()\nhas_ggplot \u003c- require(ggplot2)  # Attach if installed\n\nvec \u003c- 1:10\nrandom_sample \u003c- runif(10)\norderings \u003c- data.frame(\n  \"Position\" = as.integer(vec),\n  \"center_max\" = center_max(vec),\n  \"center_min\" = center_min(vec),\n  \"position_max\" = position_max(vec, position = 3),\n  \"position_min\" = position_min(vec, position = 3),\n  \"pair_extremes\" = pair_extremes_vec(vec),\n  \"rev_windows\" = rev_windows_vec(vec, window_size = 3),\n  \"closest_to\" = closest_to_vec(vec, origin_fn = create_origin_fn(median)),\n  \"furthest_from\" = furthest_from_vec(vec, origin = 5),\n  \"random_sample\" = random_sample,\n  \"flipped_median\" = flip_values_vec(random_sample, origin_fn=create_origin_fn(median)),\n  stringsAsFactors = FALSE\n) \n\n# Convert to long format for plotting\nif (has_tidyr){\n  orderings \u003c- orderings %\u003e% \n    tidyr::gather(key = \"Method\", value = \"Value\", 2:(ncol(orderings))) \n}\n\ngg_line_alpha \u003c- .4\ngg_base_line_size \u003c- .3\n\n```\n\n\n\u003c!-- Note: The `kable()` function simply **formats** the output and is not required. --\u003e\n\nWhile we can use the functions with `data.frames`, we showcase many of them with a `vector` for simplicity.\nAt times, we use the `*_vec()` version of a function in order to get the output as a `vector` instead of a `data.frame`.\n\nThe functions work with grouped `data.frames` and in `magrittr` pipelines (`%\u003e%`). \n\n## Rearranger examples\n\nRearrangers change the order of the data points.\n\n### Center min/max\n\n```{r}\ncenter_max(data = 1:10)\n```\n\n```{r}\ncenter_min(data = 1:10)\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=6, fig.height=3.5}\nif (has_ggplot \u0026\u0026 has_tidyr){\n  \n  # Plot centering methods\n  orderings %\u003e% \n    dplyr::filter(Method %in% c(\"center_min\", \"center_max\")) %\u003e% \n    ggplot(aes(x = Position, y = Value, color = Method)) + \n    geom_line(alpha = gg_line_alpha) + \n    geom_point() + \n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_x_continuous(breaks = c(2, 4, 6, 8, 10)) +\n    scale_y_continuous(breaks = c(2, 4, 6, 8, 10)) +\n    scale_colour_brewer(palette = \"Dark2\")\n  \n}\n```\n\n### Position min/max\n\n```{r}\nposition_max(data = 1:10, position = 3)\n```\n\n```{r}\nposition_min(data = 1:10, position = 3)\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=6, fig.height=3.5}\nif (has_ggplot \u0026\u0026 has_tidyr){\n\n  # Plot positioning methods  \n  orderings %\u003e% \n    dplyr::filter(Method %in% c(\"position_min\", \"position_max\")) %\u003e% \n    ggplot(aes(x = Position, y = Value, color = Method)) + \n    geom_line(alpha = gg_line_alpha) + \n    geom_point() +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_x_continuous(breaks = c(2, 4, 6, 8, 10)) +\n    scale_y_continuous(breaks = c(2, 4, 6, 8, 10)) +\n    scale_colour_brewer(palette = \"Dark2\")\n\n}\n```\n\n### Pair extremes\n\n```{r}\npair_extremes(data = 1:10)\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=6, fig.height=3.5}\nif (has_ggplot \u0026\u0026 has_tidyr){\n  \n  # Plot extreme pairing\n  orderings %\u003e% \n    dplyr::filter(Method == \"pair_extremes\") %\u003e% \n    ggplot(aes(x = Position, y = Value, color = Method)) + \n    geom_line(alpha = gg_line_alpha) + \n    geom_point() + \n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_x_continuous(breaks = c(2, 4, 6, 8, 10)) +\n    scale_y_continuous(breaks = c(2, 4, 6, 8, 10)) +\n    scale_colour_brewer(palette = \"Dark2\")\n    \n}\n```\n\n### Closest to / furthest from\n\nWe use the `_vec()` versions to get the reordered vectors. For `data.frames`, use `closest_to()`/`furthest_from()` instead.\n\nThe origin can be passed as either a specific coordinate (here, a value in `data`) or a function.\n\n```{r}\nclosest_to_vec(data = 1:10, origin_fn = create_origin_fn(median))\n```\n\n```{r}\nfurthest_from_vec(data = 1:10, origin = 5)\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=6, fig.height=3.5}\nif (has_ggplot \u0026\u0026 has_tidyr){\n  \n  # Plot distanced order\n  orderings %\u003e% \n    dplyr::filter(Method %in% c(\"closest_to\", \"furthest_from\")) %\u003e% \n    ggplot(aes(x = Position, y = Value, color = Method)) + \n    geom_line(alpha = gg_line_alpha) + \n    geom_point() + \n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_x_continuous(breaks = c(2, 4, 6, 8, 10)) +\n    scale_y_continuous(breaks = c(2, 4, 6, 8, 10)) +\n    scale_colour_brewer(palette = \"Dark2\")\n    \n}\n```\n\n### Reverse windows\n\nWe use the `_vec()` version to get the reordered vector. For `data.frames`, use `rev_windows()` instead.\n\n```{r}\nrev_windows_vec(data = 1:10, window_size = 3)\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=6, fig.height=3.5}\nif (has_ggplot \u0026\u0026 has_tidyr){\n    \n  # Plot windowed reversing\n  orderings %\u003e% \n    dplyr::filter(Method == \"rev_windows\") %\u003e% \n    ggplot(aes(x = Position, y = Value, color = Method)) + \n    geom_line(alpha = gg_line_alpha) + \n    geom_point() + \n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_x_continuous(breaks = c(2, 4, 6, 8, 10)) +\n    scale_y_continuous(breaks = c(2, 4, 6, 8, 10)) +\n    scale_colour_brewer(palette = \"Dark2\")\n    \n}\n```\n\n### Shuffle Hierarchy\n\nWhen having a `data.frame` with multiple grouping columns, we can shuffle them one column (hierarchical level) at a time:\n\n```{r eval=FALSE}\n# Shuffle a given data frame 'df'\nshuffle_hierarchy(df, group_cols = c(\"a\", \"b\", \"c\"))\n```\n\nThe columns are shuffled one at a time, as so:\n\n\u003cdiv style=\"width: 100%; text-align: center; display: block;\"\u003e\n\u003cimg src='https://raw.githubusercontent.com/LudvigOlsen/readme_plots/master/rearrr_plots/shuffle_hierarchy.gif' width=\"175\" style=\"padding-bottom:28px !important; padding-right:28px !important;\" /\u003e\n\u003c/div\u003e\n\n\n## Mutator examples\n\nMutators change the values of the data points.\n\n\n### Rotate values\n\n2-dimensional rotation:\n\n```{r}\n# Set seed for reproducibility\nxpectr::set_test_seed(1)\n\n# Draw random numbers \nrandom_sample \u003c- round(runif(10), digits = 4)\nrandom_sample\n\nrotate_2d(\n  data = random_sample,\n  degrees = 60,\n  origin_fn = centroid\n)\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=6, fig.height=3.5}\nrotate_df \u003c- rotate_2d(random_sample, degrees = c(0, 72, 144, 216, 288), origin_fn = centroid)\n\nif (has_ggplot){\n  \n  # Plot rotated values\n  rotate_df %\u003e% \n    ggplot(aes(x = Index_rotated, y = Value_rotated, color = factor(.degrees))) +\n    geom_hline(yintercept = mean(random_sample), size = 0.2, alpha = gg_line_alpha, linetype=\"dashed\") +\n    geom_vline(xintercept = mean(seq_len(length(random_sample))), size = 0.2, alpha = gg_line_alpha, linetype=\"dashed\") +\n    geom_path(alpha = gg_line_alpha) + \n    geom_point() + \n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \"Index\", y=\"Value\", color=\"Degrees\")\n    \n}\n\n```\n\n3-dimensional rotation:\n\n```{r}\n# Set seed\nset.seed(3)\n\n# Create a data frame\ndf \u003c- data.frame(\n  \"x\" = 1:12,\n  \"y\" = c(1, 2, 3, 4, 9, 10, 11,\n          12, 15, 16, 17, 18),\n  \"z\" = runif(12)\n)\n\n# Perform rotation\nrotate_3d(\n  data = df,\n  x_col = \"x\",\n  y_col = \"y\",\n  z_col = \"z\",\n  x_deg = 45,\n  y_deg = 90,\n  z_deg = 135,\n  origin_fn = centroid\n)\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=6, fig.height=3.5}\nrotate_df \u003c- df %\u003e%\n  rotate_3d(x_col = \"x\",\n           y_col = \"y\",\n           z_col = \"z\",\n           x_deg = c(0, 72, 144, 216, 288),\n           y_deg = c(0, 72, 144, 216, 288),\n           z_deg = c(0, 72, 144, 216, 288),\n           origin_fn = centroid)\n\nif (has_ggplot){\n    \n  # Plot rotated values\n  rotate_df %\u003e% \n    ggplot(aes(x = x_rotated, y = y_rotated, color = .degrees_str, alpha = z_rotated)) +\n    geom_vline(xintercept = mean(df$x), size = 0.2, alpha = .4, linetype=\"dashed\") +\n    geom_hline(yintercept = mean(df$y), size = 0.2, alpha = .4, linetype=\"dashed\") +\n    geom_path(alpha = gg_line_alpha) + \n    geom_point() + \n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \"x\", y = \"y\", color = \"degrees\", alpha = \"z (opacity)\")\n    \n}\n```\n\n\n### Swirl values\n\n2-dimensional swirling:\n\n```{r}\n# Rotate values\nswirl_2d(data = rep(1, 50), radius = 95, origin = c(0, 0))\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=7.6, fig.height=8.9, eval=FALSE}\n# Swirl around the centroid\ndf_swirled \u003c- swirl_2d(\n  data = rep(1, 50),\n  radius = c(95, 96, 97, 98, 99, 100),\n  origin_fn = centroid,\n  suffix = \"\",\n  scale_fn = function(x) {\n    x ^ 1.6\n  }\n)\n\norig \u003c- df_swirled$.origin[[1]]\n\nif (has_ggplot){\n    \n  # Plot swirls\n  ggswirl1 \u003c- df_swirled %\u003e%\n    ggplot(aes(x = Index, y = Value, color = factor(.radius))) +\n    geom_point() +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \"x\", y = \"y\", color = \".radius\")\n\n}\n\ndf_swirled \u003c- df_swirled %\u003e% \n  rotate_2d(degrees = (1:36) * 10, \n           x_col = \"Index\", \n           y_col = \"Value\", \n           suffix = \"\",\n           origin = orig)\n\nif (has_ggplot){\n  \n  # Plot rotated swirls\n  ggswirl2 \u003c- df_swirled %\u003e%\n    ggplot(aes(x = Index, y = Value, color = factor(.radius))) +\n    geom_point() +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \"x\", y = \"y\", color = \".radius\")\n\n}\n\n# Expand values ^2\ndf_swirled \u003c- df_swirled %\u003e% \n  expand_distances(\n    cols = c(\"Index\", \"Value\"),\n    multiplier = 2, \n    exponentiate = T,\n    origin = orig,\n    suffix = \"\")\n\nif (has_ggplot){\n  \n  # Plot expanded swirls\n  ggswirl3 \u003c- df_swirled %\u003e%\n    ggplot(aes(x = Index, y = Value, color = factor(.radius))) +\n    geom_point() +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \"x\", y = \"y\", color = \".radius\")\n\n}\n\n# Dim values\ndf_swirled \u003c- df_swirled %\u003e% \n  mutate(o = 1) %\u003e% \n  dim_values(cols = c(\"Index\", \"Value\", \"o\"), origin = c(orig, 1), suffix = \"\")\n\nif (has_ggplot){\n  \n  # Plot rotated swirls\n  ggswirl4 \u003c- df_swirled %\u003e%\n    ggplot(aes(x = Index, y = Value, alpha = o, color = factor(.radius))) +\n    geom_point() +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \"x\", y = \"y\", color = \".radius\", alpha = \"opacity (for D)\")\n  \n  combined \u003c- (ggswirl1 + ggswirl2) / (ggswirl3 + ggswirl4) \u0026 theme(legend.position = \"bottom\")\n  combined \u003c- combined + plot_layout(guides = \"collect\")\n  combined + \n    plot_annotation(title = \"2d swirls with rotation, expansion and dimming\",\n                    subtitle = \"A: 2d swirls,  B: Rotated A, C: Expanded B, D: Dimmed C\",\n                    caption = \"Distances in A are scaled by d^1.6\",\n                    tag_levels = 'A')\n\n}\n\n```\n\n\u003cdiv style=\"width: 100%; text-align: center; display: block; padding-top:20px;\"\u003e\n\u003cimg src='https://raw.githubusercontent.com/LudvigOlsen/readme_plots/master/rearrr_plots/patchwork_examples/swirl2d_patchwork_plot.png' width=\"630\" /\u003e\n\u003c/div\u003e\n\n3-dimensional swirling:\n\n```{r}\n# Set seed\nset.seed(4)\n\n# Create a data frame\ndf \u003c- data.frame(\n  \"x\" = 1:50,\n  \"y\" = 1:50,\n  \"z\" = 1:50,\n  \"r1\" = runif(50),\n  \"r2\" = runif(50) * 35,\n  \"o\" = 1,\n  \"g\" = rep(1:5, each = 10)\n)\n\n# They see me swiiirling\nswirl_3d(\n  data = df,\n  x_radius = 45,\n  x_col = \"x\",\n  y_col = \"y\",\n  z_col = \"z\",\n  origin = c(0, 0, 0),\n  keep_original = FALSE\n)\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=7.6, fig.height=8.1, eval=FALSE}\n\n# 1st plot\n\ndf_swirled \u003c- swirl_3d(\n  data = df,\n  x_col = \"x\",\n  y_col = \"y\",\n  z_col = \"z\",\n  x_radius = c(100, 0, 0),\n  y_radius = c(0, 100, 0),\n  z_radius = c(0, 0, 100),\n  origin_fn = centroid\n)\n\nif (has_ggplot){\n  \n  ggswirl_3d_1 \u003c- df_swirled %\u003e% \n    ggplot(aes(x = x_swirled, y = y_swirled, color = .radius_str, alpha = z_swirled)) +\n    geom_path(alpha = gg_line_alpha) +\n    geom_point() +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \"x\", y = \"y\", color = \"radius\", alpha = \"z (opacity)\")\n\n}\n\n\n# 2nd plot\n\ndf_swirled \u003c- swirl_3d(\n  data = df,\n  x_col = \"x\",\n  y_col = \"y\",\n  z_col = \"z\",\n  x_radius = c(50, 0, 0),\n  y_radius = c(0, 50, 0),\n  z_radius = c(0, 0, 50),\n  origin_fn = centroid\n)\n\nif (has_ggplot){\n  \n  ggswirl_3d_2 \u003c- df_swirled %\u003e% \n    ggplot(aes(x = x_swirled, y = y_swirled, color = .radius_str, alpha = z_swirled)) +\n    geom_path(alpha = gg_line_alpha) +\n    geom_point() +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \"x\", y = \"y\", color = \"radius\", alpha = \"z (opacity)\")\n\n}\n\n# 3rd plot\n\ndf_swirled \u003c- swirl_3d(\n  data = df,\n  x_col = \"x\",\n  y_col = \"y\",\n  z_col = \"z\",\n  x_radius = c(25, 50, 25, 25),\n  y_radius = c(50, 75, 100, 25),\n  z_radius = c(75, 25, 25, 25),\n  origin_fn = centroid,\n  scale_fn = function(x) {\n    x^0.81\n  }\n)\n\nif (has_ggplot){\n  \n  ggswirl_3d_3 \u003c- df_swirled %\u003e% \n    ggplot(aes(x = x_swirled, y = y_swirled, color = .radius_str, alpha = z_swirled)) +\n    geom_path(alpha = gg_line_alpha) +\n    geom_point() +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \"x\", y = \"y\", color = \"radius\", alpha = \"z (opacity)\")\n\n}\n\n# 4th plot\n\ndf_swirled \u003c- swirl_3d(\n  data = df,\n  x_col = \"r1\",\n  y_col = \"r2\",\n  z_col = \"o\",\n  x_radius = c(0, 0, 0, 0),\n  y_radius = c(0, 30, 60, 90),\n  z_radius = c(10, 10, 10, 10),\n  origin_fn = centroid\n)\n\n# Not let's rotate it every 10 degrees\ndf_rotated \u003c- df_swirled %\u003e%\n  rotate_3d(\n    x_col = \"r1_swirled\",\n    y_col = \"r2_swirled\",\n    z_col = \"o_swirled\",\n    x_deg = rep(0, 36),\n    y_deg = rep(0, 36),\n    z_deg = (1:36) * 10,\n    suffix = \"\",\n    origin = df_swirled$.origin[[1]])\n\nif (has_ggplot){\n  \n  ggswirl_3d_4 \u003c- df_rotated %\u003e% \n    ggplot(aes(x = r1_swirled, y = r2_swirled, color = .degrees_str,  alpha = o_swirled)) +\n    geom_point(show.legend = FALSE) +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    # scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \"r1\", y = \"r2\", color = \"radius\", alpha = \"o (opacity)\")\n  \n  combined \u003c- (ggswirl_3d_1 + ggswirl_3d_2) / (ggswirl_3d_3 + ggswirl_3d_4) \u0026 theme(legend.position = \"none\")\n  # combined \u003c- combined + plot_layout(guides = \"collect\")\n  combined + \n    plot_annotation(title = \"3d swirls\",\n                    subtitle = \"ABC: 3d swirls, D: rotated 3d swirls\",\n                    caption = \"Distances in C are scaled by d^0.81\",\n                    tag_levels = 'A')\n\n}\n```\n\n\u003cdiv style=\"width: 100%; text-align: center; display: block; padding-top:20px;\"\u003e\n\u003cimg src='https://raw.githubusercontent.com/LudvigOlsen/readme_plots/master/rearrr_plots/patchwork_examples/swirl3d_patchwork_plot.png' width=\"630\" /\u003e\n\u003c/div\u003e\n\n### Expand distances\n\n```{r}\n# 1d expansion\nexpand_distances(\n  data = random_sample,\n  multiplier = 3,\n  origin_fn = centroid,\n  exponentiate = TRUE\n)\n```\n\n2d expansion:\n\n```{r echo=FALSE, fig.align='center', fig.width=6, fig.height=3.5}\nxpectr::set_test_seed(36)\nrandom_x \u003c- runif(10)\nrandom_y \u003c- runif(10)\nexpand_df \u003c- purrr::map_dfr(\n  .x = c(1, 2, 3, 4, 5),\n  .f = function(exponent) {\n    expand_distances(\n      data.frame(\"x\" = random_x,\n                 \"y\" = random_y),\n      cols = c(\"x\", \"y\"),\n      multiplier = exponent,\n      origin_fn = centroid,\n      exponentiate = TRUE\n    )\n  }\n)\n\nif (has_ggplot){\n  \n  # Plot rotated values\n  expand_df %\u003e% \n    ggplot(aes(x = x_expanded, y = y_expanded, color = factor(.exponent))) +\n    geom_hline(yintercept = mean(random_y), size = 0.2, alpha = gg_line_alpha, linetype=\"dashed\") +\n    geom_vline(xintercept = mean(random_x), size = 0.2, alpha = gg_line_alpha, linetype=\"dashed\") +\n    geom_path(alpha = gg_line_alpha) + \n    geom_point() + \n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \"x\", y=\"y\", color=\"Exponent\")\n\n}\n  \nxpectr::set_test_seed(36) # for next section\n```\n\nExpand differently in each axis:\n\n```{r}\n# Expand x-axis and contract y-axis\nexpand_distances_each(\n  data.frame(\"x\" = runif(10),\n             \"y\" = runif(10)),\n  cols = c(\"x\", \"y\"),\n  multipliers = c(7, 0.5),\n  origin_fn = centroid\n)\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=6, fig.height=3.5}\nrand_df \u003c- data.frame(\"x\" = random_x,\n                      \"y\" = random_y)\nexpand_df \u003c- purrr::map2_dfr(\n  .x = c(7, 1),\n  .y = c(0.5, 1),\n  .f = function(m1, m2) {\n    expand_distances_each(\n      rand_df,\n      cols = c(\"x\", \"y\"),\n      multipliers = c(m1, m2),\n      origin_fn = centroid\n    )\n  }\n)\n\nif (has_ggplot){\n  \n  # Plot rotated values\n  expand_df %\u003e% \n    ggplot(aes(x = x_expanded, y = y_expanded, color = factor(.multipliers_str))) +\n    geom_hline(yintercept = mean(random_y), size = 0.2, alpha = gg_line_alpha, linetype = \"dashed\") +\n    geom_vline(xintercept = mean(random_x), size = 0.2, alpha = gg_line_alpha, linetype = \"dashed\") +\n    geom_path(alpha = gg_line_alpha) + \n    geom_point() + \n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \"x\", y = \"y\", color = \"Multiplier\")\n    \n}\n\n```\n\n\n### Cluster groups\n\n```{r}\n# Set seed for reproducibility\nxpectr::set_test_seed(3)\n\n# Create data frame with random data and a grouping variable\ndf \u003c- data.frame(\n  \"x\" = runif(50),\n  \"y\" = runif(50),\n  \"g\" = rep(c(1, 2, 3, 4, 5), each = 10)\n) \n\ncluster_groups(\n  data = df, \n  cols = c(\"x\", \"y\"), \n  group_col = \"g\"\n)\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=6, fig.height=3.5}\ndf_clustered \u003c- cluster_groups(df, cols = c(\"x\", \"y\"), group_col = \"g\")\n\nif (has_ggplot){\n  \n  ggplot(df_clustered, aes(x = x_clustered, y = y_clustered, color = factor(g))) +\n    # Original data\n    geom_point(aes(x = x, y = y), alpha = 0.3, size = 0.8) +\n    # Clustered data\n    geom_point() +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \"x\", y = \"y\", color = \"g\", caption = \"Semi-transparent points are the original data points.\")\n\n}\n  \ndf_clustered \u003c- df_clustered %\u003e% \n  dplyr::select(x_clustered, y_clustered, g)\n```\n\n\n### Dim values\n\n```{r}\n# Add a column with 1s\ndf_clustered$o \u003c- 1\n\n# Dim the \"o\" column based on the data point's distance \n# to the most central point in the cluster\ndf_clustered %\u003e% \n  dplyr::group_by(g) %\u003e% \n  dim_values(\n    cols = c(\"x_clustered\", \"y_clustered\"), \n    dim_col = \"o\",\n    origin_fn = most_centered\n  )\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=6, fig.height=3.5}\ndf_dimmed \u003c- df_clustered %\u003e% \n  dplyr::group_by(g) %\u003e% \n  dim_values(cols = c(\"x_clustered\", \"y_clustered\", \"o\"), origin_fn = most_centered)\n\nif (has_ggplot){\n  \n  ggplot(df_dimmed, aes(x = x_clustered, y = y_clustered, alpha = o_dimmed, color = factor(g))) +\n    geom_point() +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \"x\", y = \"y\", color = \"g\", alpha = \"o_dimmed\")\n  \n}\n```\n\n### Flip values\n\n```{r}\n# The median value to flip around\nmedian(random_sample)\n\n# Flip the random numbers around the median\nflip_values(\n  data = random_sample, \n  origin_fn = create_origin_fn(median)\n)\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=6, fig.height=3.5}\nif (has_ggplot \u0026\u0026 has_tidyr){\n    \n  # Plot flipped values\n  orderings %\u003e% \n    dplyr::filter(Method %in% c(\"random_sample\", \"flipped_median\")) %\u003e% \n    ggplot(aes(x = Position, y = Value, color = Method)) + \n    geom_line(alpha = gg_line_alpha) + \n    geom_point() + \n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_x_continuous(breaks = c(2, 4, 6, 8, 10)) +\n    scale_colour_brewer(palette = \"Dark2\")\n    \n}\n```\n\n\n## Forming examples\n\n### Circularize points\n\n```{r}\ncircularize(runif(200))\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=7.6, fig.height=4.25, eval=FALSE}\nxpectr::set_test_seed(10)\n\n# Create a data frame\ndf \u003c- data.frame(\n  \"y\" = runif(200)\n)\n\ndf_circ \u003c- circularize(df, y_col = \"y\")\n\nif (has_ggplot){\n  \n  ggcirc_1 \u003c- df_circ %\u003e%\n    ggplot(aes(x = .circle_x, y = y, color = .degrees)) +\n    geom_point() +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_distiller(palette = \"Dark2\") +\n    labs(x = \".circle_x\", y = \"y\")\n\n}\n\ndf_circ_expanded \u003c- purrr::map_dfr(\n  .x = 1:10/10,\n  .f = function(mult){\n    expand_distances(\n      data = df_circ,\n      cols = c(\".circle_x\", \"y\"),\n      multiplier = mult,\n      origin_fn = centroid)\n  })\n\nif (has_ggplot){\n  \n  ggcirc_2 \u003c- df_circ_expanded %\u003e%\n    ggplot(aes(x = .circle_x_expanded, y = y_expanded, \n               color = .degrees, alpha = 0.8*.multiplier^2)) +\n    geom_point(aes(size = 0.8*.multiplier^2)) +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_distiller(palette = \"Dark2\") + \n    labs(x = \".circle_x\", y = \"y\")\n  \n  combined \u003c- (ggcirc_1 + ggcirc_2) \u0026 theme(legend.position = \"none\")\n  combined + \n    plot_annotation(title = \"Circles\",\n                    subtitle = \"A: circularized y-values, B: contracted circles\",\n                    tag_levels = 'A')\n\n}\n\n```\n\n\u003cdiv style=\"width: 100%; text-align: center; display: block; padding-top:20px;\"\u003e\n\u003cimg src='https://raw.githubusercontent.com/LudvigOlsen/readme_plots/master/rearrr_plots/patchwork_examples/circles_patchwork_plot.png' width=\"630\" /\u003e\n\u003c/div\u003e\n\n### Hexagonalize points\n\n```{r}\nhexagonalize(runif(200))\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=7.6, fig.height=4.25, eval=FALSE}\nxpectr::set_test_seed(10)\n\n# Create a data frame\ndf \u003c- data.frame(\n  \"y\" = runif(200)\n)\n\ndf_hex \u003c- hexagonalize(df, y_col = \"y\")\n\nif (has_ggplot){\n  \n  gghex_1 \u003c- df_hex %\u003e%\n    ggplot(aes(x = .hexagon_x, y = y, color = .edge)) +\n    geom_point() +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \".hexagon_x\", y = \"y\")\n\n}\n\ndf_hex_expanded \u003c- purrr::map_dfr(\n  .x = 1:5/10*2,\n  .f = function(mult){\n    expand_distances(\n      data = df_hex,\n      cols = c(\".hexagon_x\", \"y\"),\n      multiplier = mult,\n      exponentiate = TRUE,\n      origin_fn = centroid)\n  })\n\nif (has_ggplot){\n\n  gghex_2 \u003c- df_hex_expanded %\u003e%\n    ggplot(aes(x = .hexagon_x_expanded, y = y_expanded, \n               color = .edge, alpha = 0.8*.exponent^2)) +\n    geom_point(aes(size = 0.8*.exponent^2)) +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \".hexagon_x\", y = \"y\")\n  \n  combined \u003c- (gghex_1 + gghex_2) \u0026 theme(legend.position = \"none\")\n  combined + \n    plot_annotation(title = \"Hexagons\",\n                    subtitle = \"A: hexagonalized y-values, B: contracted hexagons\",\n                    tag_levels = 'A')\n\n}\n\n```\n\n\u003cdiv style=\"width: 100%; text-align: center; display: block; padding-top:20px;\"\u003e\n\u003cimg src='https://raw.githubusercontent.com/LudvigOlsen/readme_plots/master/rearrr_plots/patchwork_examples/hexagons_patchwork_plot.png' width=\"630\" /\u003e\n\u003c/div\u003e\n\n### Square points\n\n```{r}\nsquare(runif(200))\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=7.6, fig.height=4.25, eval=FALSE}\n\ndf_sq \u003c- square(df, y_col = \"y\")\n\nif (has_ggplot){\n  \n  ggsq_1 \u003c- df_sq %\u003e%\n    ggplot(aes(x = .square_x, y = y, color = .edge)) +\n    geom_point() +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \".square_x\", y = \"y\")\n\n}\n\ndf_sq_expanded \u003c- purrr::map_dfr(\n  .x = c(1, 0.75, 0.5, 0.25, 0.125),\n  .f = function(mult){\n    expand_distances(\n      data = df_sq,\n      cols = c(\".square_x\", \"y\"),\n      multiplier = mult,\n      origin_fn = centroid)\n  }) %\u003e% \n  swirl_2d(\n    radius = 0.3,\n    x_col = \".square_x_expanded\",\n    y_col = \"y_expanded\",\n    origin_fn = centroid,\n    suffix = \"\",\n    origin_col_name = NULL\n  )\n\nif (has_ggplot){\n\n  ggsq_2 \u003c- df_sq_expanded %\u003e%\n    ggplot(aes(x = .square_x_expanded, y = y_expanded, \n               color = .edge, alpha = 0.8*.multiplier^2)) +\n    geom_point(aes(size = 0.8*.multiplier^2)) +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \".square_x\", y = \"y\")\n  \n  combined \u003c- (ggsq_1 + ggsq_2) \u0026 theme(legend.position = \"none\")\n  combined + \n    plot_annotation(title = \"Squares\",\n                    subtitle = \"A: squared y-values, B: contracted and swirled squares\",\n                    tag_levels = 'A')\n\n}\n\n```\n\n\u003cdiv style=\"width: 100%; text-align: center; display: block; padding-top:20px;\"\u003e\n\u003cimg src='https://raw.githubusercontent.com/LudvigOlsen/readme_plots/master/rearrr_plots/patchwork_examples/squares_patchwork_plot.png' width=\"630\" /\u003e\n\u003c/div\u003e\n\n### Triangularize points\n\n```{r}\ntriangularize(runif(200))\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=7.6, fig.height=4.25, eval=FALSE}\nxpectr::set_test_seed(10)\n\n# Create a data frame\ndf \u003c- data.frame(\n  \"y\" = runif(200)\n)\n\ndf_tri \u003c- triangularize(df, y_col = \"y\")\n\nif (has_ggplot){\n  \n  ggtri_1 \u003c- df_tri %\u003e%\n    ggplot(aes(x = .triangle_x, y = y, color = .edge)) +\n    geom_point() +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") +\n    labs(x = \".triangle_x\", y = \"y\")\n\n}\n\norigin \u003c- centroid(df_tri$.triangle_x, df_tri$y)\ndf_tri_expanded \u003c- purrr::map_dfr(\n  .x = 1:10/10,\n  .f = function(mult){\n    expand_distances(\n      data = df_tri,\n      cols = c(\".triangle_x\", \"y\"),\n      multiplier = mult,\n      exponentiate = TRUE, \n      add_one_exp = FALSE,\n      origin = origin)\n  }) %\u003e% \n  rotate_2d(\n    degrees = 90,\n    x_col = \".triangle_x_expanded\",\n    y_col = \"y_expanded\",\n    suffix = \"\",\n    origin = origin\n  )\n\nif (has_ggplot){\n\n  ggtri_2 \u003c- df_tri_expanded %\u003e%\n    ggplot(aes(x = .triangle_x_expanded, y = y_expanded, \n               color = .edge, alpha = 0.8*.exponent^2)) +\n    geom_point() +\n    theme_minimal(base_line_size = gg_base_line_size) + \n    scale_colour_brewer(palette = \"Dark2\") + \n    labs(x = \".triangle_x\", y = \"y\")\n  \n  combined \u003c- (ggtri_1 + ggtri_2) \u0026 theme(legend.position = \"none\")\n  combined + \n    plot_annotation(title = \"Triangles\",\n                    subtitle = \"A: triangularized y-values, B: expanded and rotated triangles\",\n                    tag_levels = 'A')\n\n}\n\n```\n\n\u003cdiv style=\"width: 100%; text-align: center; display: block; padding-top:20px;\"\u003e\n\u003cimg src='https://raw.githubusercontent.com/LudvigOlsen/readme_plots/master/rearrr_plots/patchwork_examples/triangles_patchwork_plot.png' width=\"630\" /\u003e\n\u003c/div\u003e\n\n## Generators\n\n### Generate clusters\n\n```{r echo=FALSE, fig.align='center', fig.width=6, fig.height=3.5}\nxpectr::set_test_seed(10)\n```\n\n```{r}\ngenerate_clusters(\n  num_rows = 50,\n  num_cols = 5,\n  num_clusters = 5,\n  compactness = 1.6\n)\n```\n\n```{r echo=FALSE, fig.align='center', fig.width=6, fig.height=3.5}\nxpectr::set_test_seed(10)\n\ndf_clusters \u003c- generate_clusters(\n  num_rows = 50, num_cols = 5,\n  num_clusters = 5, compactness = 1.6\n) \n\nif (has_ggplot){\n  \n  df_clusters %\u003e% \n    ggplot(\n      aes(x = D1, y = D2, color = .cluster)) +\n      geom_point() +\n      theme_minimal(base_line_size = gg_base_line_size) + \n      scale_colour_brewer(palette = \"Dark2\") + \n      labs(x = \"D1\", y = \"D2\", color = \"Cluster\")\n  \n}\n\n```\n\n\n## Utilities\n\n### Converters\n\n| Function              | Description                                                           |\n|:----------------------|:----------------------------------------------------------------------|\n|`radians_to_degrees()` |Converts radians to degrees.                                           |\n|`degrees_to_radians()` |Converts degrees to radians.                                           |\n\n### Scalers\n\n| Function              | Description                                                           |\n|:----------------------|:----------------------------------------------------------------------|\n|`min_max_scale()`      |Scale values to a range.                                               |\n|`to_unit_length()`     |Scale vectors to unit length *row-wise* or *column-wise*.              |\n\n### Measuring functions\n\n| Function              | Description                                                           |\n|:----------------------|:----------------------------------------------------------------------|\n|`distance()`           |Calculates distance to an origin.                                      |\n|`angle()`              |Calculates angle between points and an origin.                         |\n|`vector_length()`      |Calculates vector length/magnitude *row-wise* or *column-wise*.        |\n\n### Helper functions\n\n| Function              | Description                                                           |\n|:----------------------|:----------------------------------------------------------------------|\n|`create_origin_fn()`   |Creates function for finding origin coordinates (like `centroid()`).   |\n|`centroid()`           |Calculates the mean of each supplied vector/column.                    |\n|`most_centered()`      |Finds coordinates of data point closest to the centroid.               |\n|`is_most_centered()`   |Indicates whether a data point is the most centered.                   |\n|`midrange()`           |Calculates the midrange of each supplied vector/column.                |\n|`create_n_fn()`        |Creates function for finding the number of positions to move.          |\n|`median_index()`       |Calculates median index of each supplied vector.                       |\n|`quantile_index()`     |Calculates quantile of indices for each supplied vector.               |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLudvigOlsen%2Frearrr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLudvigOlsen%2Frearrr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLudvigOlsen%2Frearrr/lists"}