Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
NotificationsYou must be signed in to change notification settings

teunbrand/ggh4x

Repository files navigation

CRAN statusR-CMD-checkCodecov test coverage

The ggh4x package is a ggplot2 extension package. It provides someutility functions that don’t entirely fit within the ‘grammar ofgraphics’ concept —they can be a bit hacky— but can nonetheless beuseful in tweaking your ggplots. Examples include adjusting the sizes offacets, mapping multiple aesthetics to colours and specifying individualscales 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 asfollows:

install.packages("ggh4x")

Alternatively, you can install the development version fromGitHub with:

# install.packages("devtools")devtools::install_github("teunbrand/ggh4x")

Overview

There are a few topics explored in the package’s vignettes withexamples. Links to these topics are below.

Example

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

library(ggh4x)#> Loading required package: ggplot2library(scales)df<- transform(iris,Nester= ifelse(Species=="setosa","Short Leaves","Long Leaves"))# Basic plotg<- 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 in geom_point(aes(SW = Sepal.Width), data = ~subset(., Species == :#> Ignoring unknown aesthetics: SW#> Warning in geom_point(aes(PL = Petal.Length), data = ~subset(., Species == :#> Ignoring unknown aesthetics: PL#> Warning in geom_point(aes(PW = Petal.Width), data = ~subset(., Species == :#> 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 stripg<-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 plotg<-g+ facetted_pos_scales(x=position_scales)# Setting the sizes of panels individuallysize<-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, suggesteddependencies that are needed forguide_dendro() andstat_theodensity(), resp. ‘ggdendro’ and ‘fitdistrplus’, but thesefunctions should send a prompt in interactive sessions to install thedependencies.

Footnote

I would like to mention that there are also packages that do somesimilar things to what this package does.facetscales also has a facetfunction wherein scales can set per row/column. Theegg package can also set panel sizes.Thelemon package also hasoptions to tweak position axes. Therelayer andggnewscale packages also allowmultiple colour scales in the same plot.

Historically, many of these functions come from theggnomics package, but have beenmoved here as a package independent of Bioconductor infrastructure.

About

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

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Code of conduct

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp