Package 'ggtricks'

Title: Create Sector and Other Charts Easily Using Grammar of Graphics
Description: A collection of several geoms to create graphics, using 'ggplot2' and the Cartesian coordinate system. You use the familiar mapping 'Grammar of Graphics' without the need to do another transformation into polar coordinates.
Authors: Abdoul ISSA BIDA [aut, cre]
Maintainer: Abdoul ISSA BIDA <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0.9000
Built: 2024-11-18 04:08:36 UTC
Source: https://github.com/abdoulma/ggtricks

Help Index


Create donut plot using Cartesian coordinates system

Description

There are two arguments absolutely needed in aes() mappings:

  • cat A discrete categories vector.

  • val A numerical values vector.

Usage

geom_donut(
  mapping = NULL,
  data = NULL,
  show.legend = NA,
  na.rm = FALSE,
  inherit.aes = TRUE,
  init_angle = 0,
  x0 = 0,
  y0 = 0,
  r1 = 1,
  r2 = 0.65,
  color = "black",
  alpha = 1,
  linewidth = 0.5,
  spotlight_max = FALSE,
  spotlight_cat = NULL,
  spotlight_position = NULL,
  labels_with_tick = FALSE,
  labels_family = "",
  labels_size = 5,
  labels_col = "black",
  labels_hjust = 0.5,
  labels_vjust = 0.5,
  labels_fontface = "plain",
  labels_lineheight = 1.2,
  tick_lwd = 1,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

to be displayed in this layer

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them.

init_angle

Starting angle

x0

Init position x

y0

Init position y

r1

Outer circle radius

r2

Inner circle radius, should inferior to r1 value. r1 and r2 values are swapped otherwise.

color

Plot border colour

alpha

Filling colour transparency [0,1]

linewidth

Plot border size

spotlight_max

TRUE if we want the max value category to drive the positions of all categories

spotlight_cat

Should be a value inside categories vector. When it is provided, it is this category position which drives the positions of all categories

spotlight_position

It is used to position the category spotlighted. Value should be in c("top","right", "bottom", "left"). When a valid spotlight_cat is provided or spotlight_max is set to TRUE, the default spotlight_position value is set to TRUE

labels_with_tick

TRUE if we want tick when labelling categories

labels_family

Labels font family

labels_size

Labels font size

labels_col

Labels colour

labels_hjust

Labels horizontal adjusting

labels_vjust

Labels vertical adjusting

labels_fontface

Labels font face

labels_lineheight

Labels line height

tick_lwd

Ticks Size

...

other arguments passed on to layer().

Value

A ggplot2 layer.

Examples

my_df <- data.frame(cat = c("Apple", "Banana", "Pineapple"), val = c(2.65, 4.5, 6.25))
my_df |>
  ggplot2::ggplot() +
  geom_donut(ggplot2::aes(cat = cat, val = val)) +
  ggplot2::coord_equal()

Create donut slice plot using Cartesian coordinates system

Description

There are two arguments absolutely needed in aes() mappings:

  • cat A discrete categories vector.

  • val A numerical values vector.

Usage

geom_donut_slice(
  mapping = NULL,
  data = NULL,
  show.legend = NA,
  na.rm = FALSE,
  inherit.aes = TRUE,
  slice_angle = 180,
  init_angle = 0,
  x0 = 0,
  y0 = 0,
  r1 = 1,
  r2 = 0.65,
  color = "black",
  alpha = 1,
  linewidth = 0.5,
  slice_position = NA,
  labels_with_tick = FALSE,
  link_with_origin = FALSE,
  labels_family = "",
  labels_size = 5,
  labels_col = "black",
  labels_hjust = 0.5,
  labels_vjust = 0.5,
  labels_fontface = "plain",
  labels_lineheight = 1.2,
  tick_lwd = 1,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

to be displayed in this layer

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them.

slice_angle

Pie slice angle

init_angle

Starting angle

x0

Init position x

y0

Init position y

r1

Outer circle radius

r2

Inner circle radius, should inferior to r1 value. r1 and r2 values are swapped otherwise.

color

Plot border colour

alpha

Filling colour transparency [0,1]

linewidth

Plot border size

slice_position

Pie slice position

labels_with_tick

TRUE if we want tick when labelling categories

link_with_origin

TRUE if we want to link slice borders with origin

labels_family

Labels font family

labels_size

Labels font size

labels_col

Labels colour

labels_hjust

Labels horizontal adjusting

labels_vjust

Labels vertical adjusting

labels_fontface

Labels font face

labels_lineheight

Labels line height

tick_lwd

Ticks Size

...

other arguments passed on to layer().

Value

A ggplot2 layer.

Examples

my_df <- data.frame(cat = c("Apple", "Banana", "Pineapple"), val = c(2.65, 4.5, 6.25))
my_df |>
  ggplot2::ggplot() +
  geom_donut_slice(ggplot2::aes(cat = cat, val = val)) +
  ggplot2::coord_equal()

Create pie plot using Cartesian coordinates system

Description

There are two arguments absolutely needed in aes() mappings:

  • cat A discrete categories vector.

  • val A numerical values vector.

Usage

geom_pie(
  mapping = NULL,
  data = NULL,
  show.legend = NA,
  na.rm = FALSE,
  inherit.aes = TRUE,
  init_angle = 0,
  x0 = 0,
  y0 = 0,
  radius = 1,
  color = "black",
  alpha = 1,
  linewidth = 0.5,
  spotlight_max = FALSE,
  spotlight_cat = NULL,
  spotlight_position = NULL,
  labels_with_tick = FALSE,
  labels_family = "",
  labels_size = 5,
  labels_col = "black",
  labels_hjust = 0.5,
  labels_vjust = 0.5,
  labels_fontface = "plain",
  labels_lineheight = 1.2,
  tick_lwd = 1,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

to be displayed in this layer

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them.

init_angle

Starting angle

x0

Init position x

y0

Init position y

radius

Driving circle radius

color

Plot border colour

alpha

Filling colour transparency [0,1]

linewidth

Plot border size

spotlight_max

TRUE if we want the max value category to drive the positions of all categories

spotlight_cat

Should be a value inside categories vector. When it is provided, it is this category position which drives the positions of all categories

spotlight_position

It is used to position the category spotlighted. Value should be in c("top","right", "bottom", "left"). When a valid spotlight_cat is provided or spotlight_max is set to TRUE, the default spotlight_position value is set to TRUE

labels_with_tick

TRUE if we want tick when labelling categories

labels_family

Labels font family

labels_size

Labels font size

labels_col

Labels colour

labels_hjust

Labels horizontal adjusting

labels_vjust

Labels vertical adjusting

labels_fontface

Labels font face

labels_lineheight

Labels line height

tick_lwd

Ticks Size

...

other arguments passed on to layer().

Value

A ggplot2 layer.

Examples

my_df <- data.frame(cat = c("Apple", "Banana", "Pineapple"), val = c(2.65, 4.5, 6.25))
my_df |>
  ggplot2::ggplot() +
  geom_pie(ggplot2::aes(cat = cat, val = val)) +
  ggplot2::coord_equal()

Create a series of circles plot

Description

geom_series_circles() can be used as an alternative for single or multiple bar charts. It consists of using whole and fragments of circles to represent numerical values. As it draws circles, the geom should use with ggplot2::coord_equal() to maintain the "aspect ratio".

There are two are arguments absolutely needed in aes() mappings:

  • x A vector mapping the abscissa axis x, i.e. a character vector when x is a numerical vector, or a numerical vector when y is a character vector.

  • y A vector mapping the ordinate axis y, i.e. a numerical vector when x is a character vector or vice versa. There is a default mapping fill with value black to fill circles/fragments of circles with. It can be used in aes mapping or as a global argument for all the circles.

Usage

geom_series_circles(
  mapping = NULL,
  data = NULL,
  show.legend = NA,
  na.rm = FALSE,
  inherit.aes = TRUE,
  init_angle = 0,
  r = 0.5,
  color = NA,
  linewidth = 0.5,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

to be displayed in this layer

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them.

init_angle

Circle drawing starting angle.

r

Circle radius, should be <= 0.5.

color

Color of circles/fragments of circles borders.

linewidth

Size of circles/fragments of circles borders.

...

other arguments passed on to layer().

Value

A ggplot2 layer.

Examples

my_df <- data.frame(cat = c("Apple", "Banana", "Pineapple"), val = c(2.65, 4.5, 6.25))
my_df |>
  ggplot2::ggplot() +
  geom_series_circles(ggplot2::aes(cat, val)) +
  ggplot2::coord_equal()

Create pie slice plot using Cartesian coordinates system

Description

There are two arguments absolutely needed in aes() mappings:

  • cat A discrete categories vector.

  • val A numerical values vector.

Usage

geom_slice(
  mapping = NULL,
  data = NULL,
  show.legend = NA,
  na.rm = FALSE,
  inherit.aes = TRUE,
  slice_angle = 180,
  init_angle = 0,
  x0 = 0,
  y0 = 0,
  radius = 1,
  color = "black",
  alpha = 1,
  linewidth = 0.5,
  slice_position = NA,
  labels_with_tick = FALSE,
  labels_family = "",
  labels_size = 5,
  labels_col = "black",
  labels_hjust = 0.5,
  labels_vjust = 0.5,
  labels_fontface = "plain",
  labels_lineheight = 1.2,
  tick_lwd = 1,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

to be displayed in this layer

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them.

slice_angle

Pie slice angle

init_angle

Starting angle

x0

Init position x

y0

Init position y

radius

Driving circle radius

color

Plot border colour

alpha

Filling colour transparency [0,1]

linewidth

Plot border size

slice_position

Pie slice position

labels_with_tick

TRUE if we want tick when labelling categories

labels_family

Labels font family

labels_size

Labels font size

labels_col

Labels colour

labels_hjust

Labels horizontal adjusting

labels_vjust

Labels vertical adjusting

labels_fontface

Labels font face

labels_lineheight

Labels line height

tick_lwd

Ticks Size

...

other arguments passed on to layer().

Value

A ggplot2 layer.

Examples

my_df <- data.frame(cat = c("Apple", "Banana", "Pineapple"), val = c(2.65, 4.5, 6.25))
my_df |>
  ggplot2::ggplot() +
  geom_pie(ggplot2::aes(cat = cat, val = val)) +
  ggplot2::coord_equal()

Create series of circles labels text

Description

geom_series_text is designed to be used in concert with geom_series_circles. It renders the label mapping to the final position of the series of circles sequence.

There are three arguments absolutely needed in aes() mappings:

  • x A vector mapping the abscissa axis x, i.e. a character vector when x is a numerical vector, or a numerical vector when y is a character vector.

  • y A vector mapping the ordinate axis y, i.e. a numerical vector when x is a character vector or vice versa.

  • label Labels.

Usage

GeomSeriesText

geom_series_text(
  mapping = NULL,
  data = NULL,
  position = "identity",
  show.legend = NA,
  na.rm = FALSE,
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).

position

Position adjustment, either as a string, or the result of a call to a position adjustment function. Cannot be jointly specified with nudge_x or nudge_y.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders().

...

Other arguments passed on to layer(). These are often aesthetics, used to set an aesthetic to a fixed value, like colour = "red" or size = 3. They may also be parameters to the paired geom/stat.

Format

An object of class GeomSeriesText (inherits from GeomText, Geom, ggproto, gg) of length 1.

Value

A ggplot2 layer.

Examples

my_df <- data.frame(cat = c("Apple", "Banana", "Pineapple"), val = c(2.65, 4.5, 6.25))
my_df |>
  ggplot2::ggplot() +
  geom_series_circles(ggplot2::aes(cat, val)) +
  geom_series_text(ggplot2::aes(cat, val, label = cat)) +
  ggplot2::coord_equal()

See ggplot2::stat_identity

Description

See ggplot2::stat_identity

Usage

stat_donut(
  mapping = NULL,
  data = NULL,
  geom = "donut",
  position = "identity",
  show.legend = NA,
  na.rm = FALSE,
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

to be displayed in this layer

geom

The geometric object to use to display the data, either as a ggproto Geom subclass or as a string naming the geom stripped of the geom_ prefix (e.g. "point" rather than "geom_point")

position

Position adjustment, either as a string naming the adjustment (e.g. "jitter" to use position_jitter), or the result of a call to a position adjustment function. Use the latter if you need to change the settings of the adjustment.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them.

...

other arguments passed on to layer().

Value

A ggplot2 layer.


See ggplot2::stat_identity

Description

See ggplot2::stat_identity

Usage

stat_donut_slice(
  mapping = NULL,
  data = NULL,
  geom = "donut_slice",
  position = "identity",
  show.legend = NA,
  na.rm = FALSE,
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

to be displayed in this layer

geom

The geometric object to use to display the data, either as a ggproto Geom subclass or as a string naming the geom stripped of the geom_ prefix (e.g. "point" rather than "geom_point")

position

Position adjustment, either as a string naming the adjustment (e.g. "jitter" to use position_jitter), or the result of a call to a position adjustment function. Use the latter if you need to change the settings of the adjustment.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them.

...

other arguments passed on to layer().

Value

A ggplot2 layer.


See ggplot2::stat_identity

Description

See ggplot2::stat_identity

Usage

stat_pie(
  mapping = NULL,
  data = NULL,
  geom = "pie",
  position = "identity",
  show.legend = NA,
  na.rm = FALSE,
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

to be displayed in this layer

geom

The geometric object to use to display the data, either as a ggproto Geom subclass or as a string naming the geom stripped of the geom_ prefix (e.g. "point" rather than "geom_point")

position

Position adjustment, either as a string naming the adjustment (e.g. "jitter" to use position_jitter), or the result of a call to a position adjustment function. Use the latter if you need to change the settings of the adjustment.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them.

...

other arguments passed on to layer().

Value

A ggplot2 layer.


See ggplot2::stat_identity

Description

See ggplot2::stat_identity

Usage

stat_series_circles(
  mapping = NULL,
  data = NULL,
  geom = "series_circles",
  position = "identity",
  show.legend = NA,
  na.rm = FALSE,
  inherit.aes = TRUE,
  init_angle = NULL,
  r = NA,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

to be displayed in this layer

geom

The geometric object to use to display the data, either as a ggproto Geom subclass or as a string naming the geom stripped of the geom_ prefix (e.g. "point" rather than "geom_point")

position

Position adjustment, either as a string naming the adjustment (e.g. "jitter" to use position_jitter), or the result of a call to a position adjustment function. Use the latter if you need to change the settings of the adjustment.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them.

init_angle

Circle drawing starting angle.

r

Circle radius, should be <= 0.5.

...

other arguments passed on to layer().

Value

A ggplot2 layer.


See ggplot2::stat_identity

Description

See ggplot2::stat_identity

Usage

stat_series_text(
  mapping = NULL,
  data = NULL,
  geom = "series_text",
  position = "identity",
  show.legend = NA,
  na.rm = FALSE,
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).

geom

The geometric object to use to display the data, either as a ggproto Geom subclass or as a string naming the geom stripped of the geom_ prefix (e.g. "point" rather than "geom_point")

position

Position adjustment, either as a string, or the result of a call to a position adjustment function. Cannot be jointly specified with nudge_x or nudge_y.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders().

...

Other arguments passed on to layer(). These are often aesthetics, used to set an aesthetic to a fixed value, like colour = "red" or size = 3. They may also be parameters to the paired geom/stat.

Value

A ggplot2 layer.


See ggplot2::stat_identity

Description

See ggplot2::stat_identity

Usage

stat_slice(
  mapping = NULL,
  data = NULL,
  geom = "slice",
  position = "identity",
  show.legend = NA,
  na.rm = FALSE,
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

to be displayed in this layer

geom

The geometric object to use to display the data, either as a ggproto Geom subclass or as a string naming the geom stripped of the geom_ prefix (e.g. "point" rather than "geom_point")

position

Position adjustment, either as a string naming the adjustment (e.g. "jitter" to use position_jitter), or the result of a call to a position adjustment function. Use the latter if you need to change the settings of the adjustment.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them.

...

other arguments passed on to layer().

Value

A ggplot2 layer.