https://github.com/shahriar-siham/roundrect
An improved version of the `grid` package's rounded rectangles, allowing each corner to have a different radius instead of a uniform one. This package also provides more intuitive parameter names for easier usage. Customize fill color, border properties, opacity, and more with a simple function call.
https://github.com/shahriar-siham/roundrect
custom geometry ggplot2 graphics grid indiv plotting r rounded roundre rpacka rpackages visua
Last synced: 5 months ago
JSON representation
An improved version of the `grid` package's rounded rectangles, allowing each corner to have a different radius instead of a uniform one. This package also provides more intuitive parameter names for easier usage. Customize fill color, border properties, opacity, and more with a simple function call.
- Host: GitHub
- URL: https://github.com/shahriar-siham/roundrect
- Owner: shahriar-siham
- License: other
- Created: 2025-02-25T11:25:47.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-08-20T21:04:44.000Z (6 months ago)
- Last Synced: 2025-08-30T18:32:41.651Z (6 months ago)
- Topics: custom, geometry, ggplot2, graphics, grid, indiv, plotting, r, rounded, roundre, rpacka, rpackages, visua
- Language: R
- Homepage:
- Size: 42 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# `roundrect` - Custom Rounded Rectangle Drawing in R
`roundrect` is an R package that allows you to easily draw custom rounded rectangles with individually adjustable corner radii. Unlike the `grid` package's `grid.roundrect()` that applies the same radius to all corners, this package enables you to set different radii for each corner of the rectangle, making it more flexible for various graphical needs.
## Features
- Draw a rounded rectangle with customizable corner radii.
- Easily adjust rectangle position, size, border color, and fill color.
- Control opacity, border width, and border style.
- Straightforward parameter names for easier understanding and use.
## Installation
You can install the package from GitHub using the `devtools` package:
```R
# Install devtools if not already installed
install.packages("devtools")
# Install roundrect from GitHub
devtools::install_github("shahriar-siham/roundrect")
```
## Example
```R
library(roundrect)
round_rect(
fill = "#e43a59",
border = NA,
scale = c(0.5, 0.5),
corners = c(0.25, 0.05, 0.25, 0.05)
)
```
## Integration with ggplot2
`roundrect` also integrates with **ggplot2**, allowing you to draw rounded rectangles directly in plots. Simply use `geom_roundrect()` as a drop-in replacement for `geom_col()`.
```R
library(roundrect)
library(ggplot2)
library(grid)
df <- data.frame(x = c("A", "B", "C"), y = c(3, 5, 2))
ggplot(df, aes(x, y)) +
geom_roundrect(fill = grid::linearGradient(c('#ff304e', '#ef407c')), r = 0.075) +
theme_minimal()
```
## Parameters:
- `position`: A vector specifying the x and y positions of the rectangle (default: `c(0.5, 0.5)`).
- `scale`: A vector specifying the width and height of the rectangle (default: `c(1, 1)`).
- `corners`: A vector specifying the radii of the corners (clockwise) (default: `c(0.15, 0.15, 0.15, 0.15)`).
- `opacity`: Opacity of the rectangle (default: `1`).
- `fill`: The fill color of the rectangle (default: `NA`).
- `border`: The border color of the rectangle (default: `"black"`).
- `border_width`: The width of the border (default: `1`).
- `border_type`: The type of the border (e.g., "solid", "dashed") (default: `"solid"`).
- `border_cap`: The style of the border cap (e.g., "round", "butt") (default: `"round"`).
- `output_as_grob`: Whether to return the grob object instead of drawing it (default: `FALSE`).
- `name`: The name of the grob object (optional).
## License
This package is licensed under the MIT License.