ggh4x
ggplot extension: options for tailored facets, multiple colourscales and miscellaneous
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (16.6%) to scientific vocabulary
Keywords
ggplot-extension
ggplot2
Last synced: 6 months ago
·
JSON representation
Repository
ggplot extension: options for tailored facets, multiple colourscales and miscellaneous
Basic Info
- Host: GitHub
- Owner: teunbrand
- License: other
- Language: R
- Default Branch: main
- Homepage: https://teunbrand.github.io/ggh4x/
- Size: 71.1 MB
Statistics
- Stars: 657
- Watchers: 8
- Forks: 40
- Open Issues: 5
- Releases: 12
Topics
ggplot-extension
ggplot2
Created about 6 years ago
· Last pushed 9 months ago
Metadata Files
Readme
Changelog
License
Code of conduct
README.Rmd
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "80%",
fig.align = "center",
dev = "ragg_png",
dpi = 176
)
```
# ggh4x
[](https://CRAN.R-project.org/package=ggh4x)
[](https://github.com/teunbrand/ggh4x/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/teunbrand/ggh4x)
The ggh4x package is a ggplot2 extension package. It provides some utility functions that don't entirely fit within the 'grammar of graphics' concept ---they can be a bit hacky--- but can nonetheless be useful in tweaking your ggplots. Examples include adjusting the sizes of facets, mapping multiple aesthetics to colours and specifying individual scales for facets. Besides this, it is also a small collection of geoms, facets, positions, guides and stats.
## Installation
You can install the most recent stable version of ggh4x from CRAN as follows:
``` r
install.packages("ggh4x")
```
Alternatively, you can install the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("teunbrand/ggh4x")
```
## Overview
There are a few topics explored in the package's vignettes with examples. Links to these topics are below.
* Options to tailor [facets](https://teunbrand.github.io/ggh4x/articles/Facets.html), including:
* Additional options for axis labelling and placement in [extended facets](https://teunbrand.github.io/ggh4x/articles/Facets.html#extended-facets-1).
* [Nested facets](https://teunbrand.github.io/ggh4x/articles/Facets.html#nested-facets) that have strips that can span multiple panels.
* Custom layouts in [manual facets](https://teunbrand.github.io/ggh4x/articles/Facets.html#manual-facets-1).
* More types of [strips](https://teunbrand.github.io/ggh4x/articles/Facets.html#strips-1) to use in facets.
* Adjusting the [position scales](https://teunbrand.github.io/ggh4x/articles/Facets.html#position-scales) on a per-panel basis.
* Varying the [size of panels](https://teunbrand.github.io/ggh4x/articles/Facets.html#sizes) without being limited to the global `aspect.ratio` or fixed coordinates.
* There are some [stat layers](https://teunbrand.github.io/ggh4x/articles/Statistics.html) that can make it easier to plot. These stat layers can:
* overlaying the [theoretical density](https://teunbrand.github.io/ggh4x/articles/Statistics.html#theoretical-densities) of several distributions, which are computed with the **fitdistrplus** package.
* draw a trend line of your data with a [rolling kernel](https://teunbrand.github.io/ggh4x/articles/Statistics.html#rolling-kernels).
* plainly [transform x and y](https://teunbrand.github.io/ggh4x/articles/Statistics.html#function-x-y) position in a group-wise manner.
* calculate [run-length encodings](https://teunbrand.github.io/ggh4x/articles/Statistics.html#run-length-encoding) of your data.
## Example
Below you'll find an example that illustrates some of the features of ggh4x.
```{r multicolour}
library(ggh4x)
library(scales)
df <- transform(
iris,
Nester = ifelse(Species == "setosa", "Short Leaves", "Long Leaves")
)
# Basic plot
g <- ggplot(df, aes(Sepal.Width, Sepal.Length)) +
theme_classic() +
theme(strip.background = element_blank())
# For making a plot with multiple colour scales, we'd first need to make layers
# with alternative aesthetics. We'll choose a colour scale for every species.
# This will produce a few warnings, as ggplot2 doesn't know how to deal with
# the alternative aesthetics.
g <- g +
geom_point(aes(SW = Sepal.Width),
data = ~ subset(., Species == "setosa")) +
geom_point(aes(PL = Petal.Length),
data = ~ subset(., Species == "versicolor")) +
geom_point(aes(PW = Petal.Width),
data = ~ subset(., Species == "virginica"))
# These alternative aesthetics don't mean a lot until we add a multi-colour
# scale to the plot. We need to specify our alternative aesthetics and colours
# for every scale. Arguments provided as lists are passed on to individual
# scales.
g <- g +
scale_colour_multi(
aesthetics = c("SW", "PL", "PW"),
name = list("Blue", "Pink", "Orange"),
colours = list(
brewer_pal(palette = "YlGnBu")(6),
brewer_pal(palette = "RdPu")(6),
brewer_pal(palette = "YlOrRd")(6)
),
guide = guide_colorbar(barheight = unit(50, "pt"))
)
g
```
```{r facets}
# We can make a facet wherein duplicated strip labels are merged into one strip
g <- g +
facet_nested(~ Nester + Species, scales = "free",
nest_line = TRUE)
# Like we did for colours, we might also want to set position scales for every
# panel individually. We set these in the same order the facets appear in.
position_scales <- list(
scale_x_reverse(guide = guide_axis(minor.ticks = TRUE)),
scale_x_continuous(labels = dollar, guide = guide_axis(cap = "both")),
scale_x_continuous(breaks = c(3, 4), expand = c(0,0))
)
# Adding the list of scales to the plot
g <- g + facetted_pos_scales(x = position_scales)
# Setting the sizes of panels individually
size <- 2 / (1 + sqrt(5))
g <- g + force_panelsizes(cols = c(1, size, size ^ 2), respect = TRUE)
g
```
## Dependency statement
The 'ggh4x' package largely takes on the same dependencies as 'ggplot2' to keep it on the lightweight side. There are two optional, suggested dependencies that are needed for `guide_dendro()` and `stat_theodensity()`, resp. 'ggdendro' and 'fitdistrplus', but these functions should send a prompt in interactive sessions to install the dependencies.
## Footnote
I would like to mention that there are also packages that do some similar things to what this package does. [facetscales](https://github.com/zeehio/facetscales) also has a facet function wherein scales can set per row/column. The [egg](https://github.com/jwdink/egg) package can also set panel sizes. The [lemon](https://github.com/stefanedwards/lemon) package also has options to tweak position axes. The [relayer](https://github.com/clauswilke/relayer) and [ggnewscale](https://github.com/cran/ggnewscale) packages also allow multiple colour scales in the same plot.
Historically, many of these functions come from the [ggnomics](https://github.com/teunbrand/ggnomics) package, but have been moved here as a package independent of Bioconductor infrastructure.
Owner
- Name: Teun van den Brand
- Login: teunbrand
- Kind: user
- Location: Amsterdam
- Company: Netherlands Cancer Institute
- Twitter: TeunvandenBrand
- Repositories: 27
- Profile: https://github.com/teunbrand
Computational PhD student in @deWitLab with an interest in chromatin biology and gene regulation.
GitHub Events
Total
- Create event: 12
- Release event: 2
- Issues event: 36
- Watch event: 79
- Delete event: 10
- Issue comment event: 38
- Push event: 31
- Pull request event: 16
- Fork event: 5
Last Year
- Create event: 12
- Release event: 2
- Issues event: 36
- Watch event: 79
- Delete event: 10
- Issue comment event: 38
- Push event: 31
- Pull request event: 16
- Fork event: 5
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Teun van den Brand | 4****d | 331 |
| Vishal Katti | v****i@e****m | 2 |
| jrmuirhead | j****1@g****m | 1 |
| AlexisDerumigny | A****y | 1 |
| Teun van den Brand | t****d@t****l | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 164
- Total pull requests: 24
- Average time to close issues: about 1 month
- Average time to close pull requests: 5 days
- Total issue authors: 93
- Total pull request authors: 5
- Average comments per issue: 2.23
- Average comments per pull request: 0.29
- Merged pull requests: 20
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 23
- Pull requests: 17
- Average time to close issues: 18 days
- Average time to close pull requests: 2 days
- Issue authors: 16
- Pull request authors: 2
- Average comments per issue: 1.26
- Average comments per pull request: 0.12
- Merged pull requests: 15
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- teunbrand (45)
- brunomioto (5)
- tjebo (4)
- pank (4)
- Yunuuuu (3)
- Ari04T (3)
- junjunlab (3)
- Breeze-Hu (2)
- davidhodge931 (2)
- yjunechoe (2)
- sergiocorreia (2)
- nonsciencemark (2)
- cms72 (2)
- bappa10085 (2)
- smouksassi (2)
Pull Request Authors
- teunbrand (17)
- davidhodge931 (2)
- AlexisDerumigny (2)
- jrmuirhead (2)
- vikatti (1)
Top Labels
Issue Labels
enhancement (17)
bug (15)
plan (5)
on hold (2)
notice (2)
wontfix (2)
documentation (2)
invalid (2)
seeking feedback (1)
help wanted (1)
The 'Maybe' Pile (1)
Pull Request Labels
enhancement (1)
documentation (1)
Spelling or grammar mistakes (1)
Dependencies
DESCRIPTION
cran
- ggplot2 >= 3.3.0 depends
- grid * imports
- gtable * imports
- lifecycle * imports
- rlang * imports
- scales * imports
- vctrs * imports
- MASS * suggests
- covr * suggests
- digest * suggests
- fitdistrplus * suggests
- ggdendro * suggests
- knitr * suggests
- rmarkdown * suggests
- stats * suggests
- testthat >= 3.0.0 suggests
- utils * suggests
- vdiffr * suggests