gg_utls: My utility functions for handling ggplot objects.

gg_utlsR Documentation

My utility functions for handling ggplot objects.

Description

My utility functions for handling ggplot objects.

Usage

gg_leg(x)

unfacet(x)

splitFacet(x)

gg_cols(n)

unfacet(x)

splitFacet(x)

gg_cols(n)

Arguments

x

ggplot class object

n

integer: numbers of colour code

Examples

## Not run: 
# gg_leg: separate a ggplot objetc to a legend and a ggplot object without legend.
gg1 <- ggplot2::ggplot(iris, ggplot2::aes(Sepal.Length, Sepal.Width, colour = Species)) +
 ggplot2::geom_point()
gg2 <- ggplot2::ggplot(iris, ggplot2::aes(Sepal.Length, Petal.Length, colour = Species)) +
 ggplot2::geom_point()

res1 <- gg_leg(gg1); res2 <- gg_leg(gg2)
gg1_nl <- res1[[1]]; gg2_nl <- res2[[1]]; lgnd <- res1[[2]]

gridExtra::grid.arrange(gg1, gg2, ncol=2)
gridExtra::grid.arrange(gridExtra::arrangeGrob(gg1_nl, gg2_nl, lgnd,
 ncol = 3, widths = c(3/7, 3/7, 1/7)))

# splitFacet: split a facet to list
gg <- ggplot2::ggplot(iris, ggplot2::aes(Sepal.Length, Petal.Length)) +
 ggplot2::geom_point() +
 ggplot2::facet_wrap(~Species)
lst <- splitFacet(gg)
do.call(gridExtra::grid.arrange, c(lst, list(ncol = 3)))

# gg_cols: Create defaoult colour code of ggplot2
cols <- gg_cols(10)
barplot(setNames(rep(1,10), cols), col = cols, las =2)


## End(Not run)


shkonishi/rsko documentation built on Feb. 21, 2023, 5:12 a.m.