MyNixOS website logo
Description

Object-Oriented Diagram Plots with 'ggplot2'.

Creates diagrams with an object-oriented approach. Geometric objects have computed properties with information about themselves (e.g., their area) or about their relationships with other objects (e.g, the distance between their edges). The objects have methods to convert them to geoms that can be plotted in 'ggplot2'.

ggdiagram

Lifecycle:stable CRANstatus ggdiagram statusbadge

The ggdiagram package takes an object-oriented approach to making diagrams and plots the results using ggplot2.

My motivation in making ggdiagram was to find a way to approach the functionality of TikZ but with the flexibility and convenience of R. The ggdiagram package is built atop S7 and is integrated with ggplot2, making heavy use of ggtext, ggforce, and ggarrow.

The ggdiagram package is not a replacement for the standard ggplot2 functions. The underlying grammar of ggplot2 is well designed for visualizing data. The ggdiagram functions are best suited for creating a small number of visual objects that interrelate. If anything, they can be thought of as extensions of ggplot2::annotate.

Installation

To install the published version from CRAN:

install.packages("ggdiagram")

You can install the development version of ggdiagram from R-universe like so:

install.packages("ggdiagram", repos = "https://wjschne.r-universe.dev")

Example

In Figure 1, we create a circle object with ob_circle and a rectangle object with ob_rectangle, placing the rectangle such that there is .5 units of separation between the two objects.

The ggdiagram function is a a wrapper for ggplot, that sets some defaults (e.g., theme_void, coord_equal, fonts, line size, etc.).

The ob_* functions have methods such that they can be added to any ggplot. Under the hood, they are first converted to an appropriate geom and then added to the ggplot object. In this case, an ob_circle is converted to a ggforce:geom_circle, and an ob_rectangle is converted to a ggforce::geom_shape.

The connect function connects the circle and rectangle at their edges with an arrow (drawn with ggarrow::geom_arrow_segment).

library(ggdiagram)
c1 <- ob_circle(radius = 1 / sqrt(pi)) 
r2 <- ob_rectangle() |>
  place(from = c1,
        where = "right", 
        sep = .5)

ggdiagram() +
  c1 +
  r2 +
  connect(c1, r2, resect = 1) 

Figure 1: Connecting a circle and a square with an arrow.

Metadata

Version

0.1.1

License

Unknown

Platforms (76)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows