teunbrand / ggh4x

ggplot extension: options for tailored facets, multiple colourscales and miscellaneous
https://teunbrand.github.io/ggh4x/
Other
554 stars 33 forks source link

Nested guide #3

Closed teunbrand closed 4 years ago

teunbrand commented 4 years ago

A guide that can deconvolute a call to interaction(a,b) and places axis labels hierarchically according to the levels. Similar to what facet_nested() does, but for discrete position scales

teunbrand commented 4 years ago

It should now be possible to use guide_axis_nested() as follows:

Data ``` r pokemon <- data.frame( name = c("Bulbasaur", "Ivysaur", "Venusaur", "Charmander", "Charmeleon", "Charizard", "Squirtle", "Wartortle", "Blastoise"), type1 = factor(rep(c("Grass", "Fire", "Water"), each = 3)), type2 = factor(rep(c("Poison", "", "Flying", ""), c(3,2,1,3))), weight = c(6.9, 13, 100, 8.5, 19, 90.5, 9, 22.5, 85.5), stringsAsFactors = FALSE ) ```
library(ggh4x)
#> Loading required package: ggplot2

ggplot(pokemon, 
       aes(weave_factors(name, type1, type2), weight)) +
  geom_col() +
  scale_x_discrete(guide = "axis_nested")

Created on 2020-04-16 by the reprex package (v0.3.0)