
<!-- README.md is generated from README.Rmd. Please edit that file -->

# ggrounded <a href="https://botan.github.io/ggrounded/"><img src="man/figures/logo.png" align="right" height="139" /></a>

<!-- badges: start -->

[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/botan/ggrounded/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/botan/ggrounded/actions/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/botan/ggrounded/branch/main/graph/badge.svg)](https://app.codecov.io/gh/botan/ggrounded?branch=main)
[![CRAN
status](https://www.r-pkg.org/badges/version/ggrounded)](https://CRAN.R-project.org/package=ggrounded)
<!-- badges: end -->

ggrounded creates bar plots with rounded corners using ggplot2.

## Installation

Install the released version of ggrounded from CRAN:

``` r
install.packages("ggrounded")
```

Or install the development version from GitHub with:

``` r
# install.packages("pak")
pak::pak("botan/ggrounded")
```

## Usage

There are two types of bar charts in ggplot2: `geom_bar()` and
`geom_col()`. `geom_bar_rounded()` and `geom_col_rounded()` are wrappers
on them for rounding the top corners. `geom_bar_rounded()` makes the
height of the bar proportional to the number of cases in each group (or
if the `weight` aesthetic is supplied, the sum of the weights).

The `radius` argument is a normalized value between `0` and `1`. Use `0`
for square corners and `1` for the maximum rounding that each bar can
safely support based on its own width and height.

``` r
library(ggrounded)
library(ggplot2)

ggplot(mpg, aes(class)) +
  geom_bar_rounded()
```

<img src="man/figures/README-example1-1.png" width="100%" />

If you want the heights of the bars to represent values in the data, use
`geom_col_rounded()` instead.

``` r
ggplot(data.frame(x = letters[1:3], y = c(2.3, 1.9, 3.2)), aes(x, y)) +
  geom_col_rounded()
```

<img src="man/figures/README-example2-1.png" width="100%" />

Use larger `radius` values when you want a more pronounced rounded top:

``` r
ggplot(data.frame(x = letters[1:3], y = c(2.3, 1.9, 3.2)), aes(x, y)) +
  geom_col_rounded(radius = 1)
```

<img src="man/figures/README-example3-1.png" width="100%" />

Histograms can use rounded bins with `geom_histogram_rounded()`:

``` r
ggplot(faithful, aes(waiting)) +
  geom_histogram_rounded(bins = 10)
#> Warning: The `drop` argument of `stat_bin()` is deprecated as of ggplot2 2.1.0.
#> ℹ Please use the `pad` argument instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.
```

<img src="man/figures/README-unnamed-chunk-4-1.png" width="100%" />

Negative values are supported too. Bars above zero keep rounded top
corners, while bars below zero round away from the baseline:

``` r
ggplot(data.frame(x = letters[1:4], y = c(2.3, -1.9, 3.2, -2.6)), aes(x, y)) +
  geom_hline(yintercept = 0, linetype = "dotted") +
  geom_col_rounded()
```

<img src="man/figures/README-example4-1.png" width="100%" />

## Code of Conduct

Please note that the ggrounded is released with a [contributor code of
conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct.html).
By contributing in this project you agree to abide by its terms.

## License

This package is released under the MIT License.
