https://github.com/nrennie/ggtextcircle
R package to plot text in a (partial) circle.
https://github.com/nrennie/ggtextcircle
r r-package
Last synced: 8 months ago
JSON representation
R package to plot text in a (partial) circle.
- Host: GitHub
- URL: https://github.com/nrennie/ggtextcircle
- Owner: nrennie
- License: cc-by-4.0
- Created: 2024-03-04T15:15:01.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-02T15:09:47.000Z (over 1 year ago)
- Last Synced: 2024-04-02T16:31:28.373Z (over 1 year ago)
- Topics: r, r-package
- Language: R
- Homepage:
- Size: 356 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-ggplot2 - ggtextcircle
README
# ggtextcircle
R package to plot text in a (partial or full) circle.
## Example
Generate some data using the {charlatan} package (only required for examples, not required for package):
```r
set.seed(123)
plot_df <- data.frame(name = charlatan::ch_name(n = 30))
```
Basic usage:
```r
ggplot(data = plot_df) +
geom_textcircle(mapping = aes(label = name))
```

With styling:
```r
ggplot(data = plot_df) +
geom_textcircle(mapping = aes(label = name), size = 3) +
scale_x_continuous(limits = c(-6, 5)) +
scale_y_continuous(limits = c(-6, 6)) +
coord_fixed() +
theme_void()
```

A more complex example (uses {ggtext} and {dplyr}):
```r
# read in #TidyTuesday leap Day data
tuesdata <- tidytuesdayR::tt_load("2024-02-27")
births <- tuesdata$births
deaths <- tuesdata$deaths
# Plot
ggplot() +
geom_textcircle(
data = dplyr::filter(births, year_birth >= 1900),
mapping = aes(label = person),
colour = "#35978f",
r = 6,
size = 2.5
) +
geom_textcircle(
data = dplyr::filter(deaths, year_death >= 1900),
mapping = aes(label = person),
colour = "#bf812d",
r = 3,
size = 2.5
) +
# annotate with {ggtext}
ggtext::geom_textbox(
data = data.frame(x = 0, y = 1.0, label = "Births and deaths on February 29th"),
mapping = aes(x = x, y = y, label = label),
hjust = 0,
fontface = "bold",
lineheight = 0.5,
fill = "transparent",
box.colour = "transparent",
size = 5,
minwidth = 0.5
) +
ggtext::geom_textbox(
data = data.frame(
x = 0, y = -0.5,
label = glue::glue("February 29 is a leap day (or 'leap year day'), an
intercalary date added periodically to create leap
years in the Julian and Gregorian calendars. Wikpedia
lists {nrow(dplyr::filter(births, year_birth >= 1900))}
births and {nrow(dplyr::filter(deaths, year_death >= 1900))}}
deaths on a leap
day since 1900.")
),
mapping = aes(x = x, y = y, label = label),
hjust = 0,
lineheight = 0.5,
fill = "transparent",
box.colour = "transparent",
size = 4,
minwidth = 0.45
) +
scale_x_continuous(limits = c(-8, 8)) +
scale_y_continuous(limits = c(-8, 8)) +
coord_fixed() +
theme_void()
```
