All Projects → teunbrand → Ggh4x

teunbrand / Ggh4x

Licence: other
ggplot extension: options for tailored facets, multiple colourscales and miscellaneous

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to Ggh4x

ggdogs
The geom you always wished for adding dogs to ggplot2
Stars: ✭ 28 (-81.08%)
Mutual labels:  ggplot2, ggplot-extension
Ggforce
Accelerating ggplot2
Stars: ✭ 640 (+332.43%)
Mutual labels:  ggplot2, ggplot-extension
Ggpointdensity
📈 📊 Introduces geom_pointdensity(): A Cross Between a Scatter Plot and a 2D Density Plot.
Stars: ✭ 286 (+93.24%)
Mutual labels:  ggplot2, ggplot-extension
Gghalves
✂️ Easy half-half geoms in ggplot2
Stars: ✭ 174 (+17.57%)
Mutual labels:  ggplot2, ggplot-extension
Ggbernie
A ggplot2 geom for adding Bernie Sanders to ggplot2
Stars: ✭ 96 (-35.14%)
Mutual labels:  ggplot2, ggplot-extension
ggbg
Miscellaneous Ggplot2 Extensions
Stars: ✭ 21 (-85.81%)
Mutual labels:  ggplot2, ggplot-extension
Ggalt
🌎 Extra Coordinate Systems, Geoms, Statistical Transformations & Scales for 'ggplot2'
Stars: ✭ 561 (+279.05%)
Mutual labels:  ggplot2, ggplot-extension
Ggsignif
Easily add significance brackets to your ggplots
Stars: ✭ 322 (+117.57%)
Mutual labels:  ggplot2, ggplot-extension
Hrbrthemes
🔏 Opinionated, typographic-centric ggplot2 themes and theme components
Stars: ✭ 899 (+507.43%)
Mutual labels:  ggplot2, ggplot-extension
Ggdistribute
ggplot2 extension for plotting distributions
Stars: ✭ 16 (-89.19%)
Mutual labels:  ggplot2, ggplot-extension
Calendr
Ready to print calendars with ggplot2
Stars: ✭ 161 (+8.78%)
Mutual labels:  ggplot2, ggplot-extension
Lemon
🍋 Lemon --- Freshing up your ggplots
Stars: ✭ 147 (-0.68%)
Mutual labels:  ggplot2, ggplot-extension
Econocharts
Microeconomics/macroeconomics charts in ggplot2
Stars: ✭ 161 (+8.78%)
Mutual labels:  ggplot2, ggplot-extension
Ggpol
🌍 Parliament diagrams and more for ggplot2
Stars: ✭ 71 (-52.03%)
Mutual labels:  ggplot2, ggplot-extension
Patchwork
The Composer of ggplots
Stars: ✭ 2,002 (+1252.7%)
Mutual labels:  ggplot2, ggplot-extension
Ggraph
Grammar of Graph Graphics
Stars: ✭ 815 (+450.68%)
Mutual labels:  ggplot2, ggplot-extension
Ggcats
The geom you always wished for adding cats to ggplot2
Stars: ✭ 34 (-77.03%)
Mutual labels:  ggplot2, ggplot-extension
Gganimate
A Grammar of Animated Graphics
Stars: ✭ 1,744 (+1078.38%)
Mutual labels:  ggplot2, ggplot-extension
Pandoc Plot
Render and include figures in Pandoc documents using your plotting toolkit of choice
Stars: ✭ 75 (-49.32%)
Mutual labels:  ggplot2
Ggimage
🎨 Use Images in ggplot2
Stars: ✭ 120 (-18.92%)
Mutual labels:  ggplot2

ggh4x

Codecov test coverage R-CMD-check CRAN status

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 development version from GitHub with:

# 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.

Example

Below you’ll find an example that illustrates some of the features of ggh4x.

library(ggh4x)
#> Loading required package: ggplot2
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"))
#> Warning: Ignoring unknown aesthetics: SW
#> Warning: Ignoring unknown aesthetics: PL
#> Warning: Ignoring unknown aesthetics: PW

# 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
# 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 = "axis_minor"),
  scale_x_continuous(labels = dollar, guide = "axis_truncated"),
  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

Footnote

I would like to mention that there are also packages that do some similar things to what this package does. facetscales also has a facet function wherein scales can set per row/colum. The egg package can also set panel sizes. The lemon package also has options to tweak position axes. The relayer and ggnewscale packages also allow multiple colour scales in the same plot.

Historically, many of these functions come from the ggnomics package, but have been moved here as a package independent of Bioconductor infrastructure.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].