ggbrace

curly braces in ggplot2.

https://github.com/nicolash2/ggbrace

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.4%) to scientific vocabulary

Keywords

brace braces bracket ggplot ggplot2 graph graphs plot r
Last synced: 6 months ago · JSON representation

Repository

curly braces in ggplot2.

Basic Info
Statistics
  • Stars: 13
  • Watchers: 1
  • Forks: 5
  • Open Issues: 0
  • Releases: 4
Topics
brace braces bracket ggplot ggplot2 graph graphs plot r
Created about 5 years ago · Last pushed 7 months ago
Metadata Files
Readme License

README.md

ggbrace

An R package that draws curly braces in ggplot2.

Table of contents

Updates

Version 0.1.1 (Feb 2024) of ggbrace removed the original geom_brace function, which plots braces within the confines of the x-y-values. The same functionality can now be achieved with stat_brace( outside = FALSE ). Additionally, the text functionality is now its own function stat_bracetext which allows for more customization of the text using the same arguments that would be used in geom_text or geom_label. By default stat_brace uses geom="text" which can be changed e.g. by stat_brace(geom="label").

Installation

Install the package from CRAN r install.packages("ggbrace") or from this git repository: r devtools::install_github("nicolash2/ggbrace")

Plotting braces

The new version of ggbrace uses only stat_brace to automatically enclose data points. stat_bracetext is used to generate fitting text.

In our example we use the iris data to create a dotplot. Then we look at how each of the three different modes draws braces to that plot.

``` r library(ggplot2) library(ggbrace) data(iris)

plt <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species, label=Species)) + geompoint() + themeclassic() + theme(legend.position="none")

plt + stat_brace() ```

Labels & Modifications

Labels

We can add labels to the braces. For that the stat_bracetext is used.

r plt + stat_brace() + stat_bracetext()

We can modify the text in the same way we would modify other text in ggplot. We can also switch between different text geoms (e.g. geom=label).

r plt + stat_brace() + stat_bracetext(size=6, angle=15, fontface="bold")

Rotation

We can rotate the braces by 90, 180 or 270 degrees via the rotate argument. Note that any changes in stat_brace also have to be made in stat_bracetext so that the text appears at the right position

r plt + stat_brace(rotate = 90) + stat_bracetext(rotate = 90)

Location

By default, the location of the brace is beside the data points by default. We can change that by setting the paramter outside to FALSE.

r plt + stat_brace(outside = FALSE)

By default, braces have a position and shape that is calculated based on their data points.The position can be changed with the parameters distance (to the data points) and outerstart (in the coordinate system). The width of the braces can be set with the width argument (absolute coordinate system units), while the bending of the brace can be set with bending (number from 0 to 1).

r plt + stat_brace(distance = 2) # the braces are put at a defined distance to the last data point of their group plt + stat_brace(outerstart = 5) # all braces are put at the same position plt + stat_brace(outerstart = 5, width = 1) # all braces get the same width plt + stat_brace(outerstart = 5, width = 1, bending = 0.1) # all braces get the same curvature

Outside of plotting area

To vizualize the brace outside of the plotting area, we can simply use two ggplot2 functions. - coord_cartesian needs to be mentioned with x and/or y range of the plotting area and the parameter clip="off" to allow plotting of objects outside of that area. - within the theme function, plot.margin needs to be set to expand the outside area. This happens with 4 numbers (above, right, below, left). This can best be achieved with the "npc" unit, as it reflects the plot units and is therefore maintained independent of the pixels, cm, etc. Other units can be seen with ?unit (under grid). r plt + stat_brace(outerstart = 4.5) + coord_cartesian(y=range(iris$Sepal.Width), clip = "off") + #for the range just use the data for the respective axis theme(plot.margin = unit(c(0.25, 0.11, 0.11, 0.11), units="npc"))

New Features - only in github version

Discrete/Categorical axis

Use discreteAxis=TRUE to ensure the braces embrace the category.

r df <- iris df$Group <- substring(iris$Species,1,1) ggplot(df, aes(x=Species, y=Sepal.Length, group=Group)) + geom_jitter() + stat_brace(discreteAxis=TRUE)

Square brackets

Use bracketType="square" to produce square brackets instead of curly ones. The bracket have the same width as the curly ones in order to comply with the text. Use the width parameter to adjust their size.

r plt + stat_brace(bracketType="square", width=.2)

Owner

  • Name: Nicolas Huber
  • Login: NicolasH2
  • Kind: user
  • Location: Monheim, Germany
  • Company: Resolve Biosciences GmbH

Data Analyst

GitHub Events

Total
  • Release event: 1
  • Delete event: 2
  • Push event: 12
  • Pull request event: 2
  • Create event: 3
Last Year
  • Release event: 1
  • Delete event: 2
  • Push event: 12
  • Pull request event: 2
  • Create event: 3

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 4
  • Total pull requests: 7
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 25 minutes
  • Total issue authors: 3
  • Total pull request authors: 3
  • Average comments per issue: 4.5
  • Average comments per pull request: 0.14
  • Merged pull requests: 7
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 2
  • Average time to close issues: N/A
  • Average time to close pull requests: less than a minute
  • Issue authors: 0
  • Pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • RoyalTS (2)
  • oushujun (1)
Pull Request Authors
  • NicolasH2 (8)
  • olivroy (2)
  • RoyalTS (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 3
  • Total downloads:
    • cran 478 last-month
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 0
    (may contain duplicates)
  • Total versions: 8
  • Total maintainers: 1
proxy.golang.org: github.com/nicolash2/ggbrace
  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 6.5%
Average: 6.7%
Dependent repos count: 6.9%
Last synced: 6 months ago
proxy.golang.org: github.com/NicolasH2/ggbrace
  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 6.5%
Average: 6.7%
Dependent repos count: 6.9%
Last synced: 6 months ago
cran.r-project.org: ggbrace

Curly Braces for 'ggplot2'

  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 478 Last month
Rankings
Dependent packages count: 28.2%
Dependent repos count: 36.1%
Average: 49.7%
Downloads: 84.7%
Maintainers (1)
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.6.0 depends
  • ggplot2 >= 3.3.1 depends
  • ggplot2 >= 3.3.1 imports