facet_nested_x
extension of facet_grid using package `ggh4x` and make grouping x
facet_nested_x(ggobj, cols, ...)
a ggplot object, which contains columns to split for x axis
string, containing columns names to be separated, separated by "+" when more than one.
other argument to pass to facet_grid(...)
a character vector, which turn p-value into significance for each element
library(ggplot2)
library(cowplot)
#> Warning: package 'cowplot' was built under R version 4.0.5
library(toolPhD)
mg <- ggplot(mtcars, aes(x = mpg, y = wt)) +
geom_point()+theme_classic()+
theme(axis.text.x = element_text(angle=90))
p1 <- ggplot(mtcars, aes(x = interaction(mpg,vs,am), y = wt)) +
geom_point()+ theme_classic()+
theme(axis.text.x = element_text(angle=90))+ggtitle("interaction of 3 columns")
p2 <- mg + facet_grid(.~vs + am , margins = TRUE)+ggtitle("facet 2 columns")
p3 <- facet_nested_x(mg,"vs + am")+ggtitle("facet and nested 2 columns")
cowplot::plot_grid(p1,p2,p3,ncol=3)
facet_nested_x(mg,"vs + am",labeller = labeller( .cols = label_both))