Package 'ggpie'

Title: Pie, Donut and Rose Pie Plots
Description: Create pie, donut and rose pie plot with 'ggplot2'.
Authors: Yabing Song [aut, cre]
Maintainer: Yabing Song <[email protected]>
License: MIT + file LICENSE
Version: 0.2.5
Built: 2024-11-08 03:42:59 UTC
Source: https://github.com/showteeth/ggpie

Help Index


Create donut plot.

Description

Create donut plot.

Usage

ggdonut(
  data,
  group_key = NULL,
  count_type = c("count", "full"),
  fill_color = NULL,
  label_info = "count",
  label_split = "[[:space:]]+",
  label_len = 40,
  label_color = "black",
  label_type = c("circle", "horizon", "none"),
  label_pos = c("in", "out"),
  label_gap = 0.05,
  label_threshold = NULL,
  label_size = 4,
  border_color = "black",
  border_size = 1,
  r0 = 1,
  r1 = 3,
  donut.label = TRUE,
  donut.label.size = 4,
  donut.label.color = "red",
  nudge_x = 1,
  nudge_y = 1
)

Arguments

data

Data frame contains full data or summarized data.

group_key

Column used to summarize the data. Default: NULL.

count_type

Data frame type, chosen from "count" and "full". "count" means summarized data and "full" means full data. Default: count.

fill_color

Colors used. Default: NULL (conduct automatic selection).

label_info

Label information type, combine from group, count, ratio. For example, use "count" , "ratio" will show count and ratio, count is main label info, ratio is in brackets. Default: count.

label_split

Pattern used to split the label, support regular expression. Default: space.

label_len

The length of label text. Used when label_split is NULL. Default: 40.

label_color

Color of the label. Default: black.

label_type

Label style, chosen from circle, horizon and none (no label). Default: circle.

label_pos

Label position, chosen from in and out. Default: in.

label_gap

Gap between label and pie plot, used when label_pos is out.

label_threshold

Threshold of the ratio to determine label position (in/out pie). Default: NULL.

label_size

Size of the label. Default: 4.

border_color

Border color. Default: black.

border_size

Border thickness. Default: 1.

r0

The radius of inner blank circle. Default: 1.

r1

The radius of outer circle. Default: 3.

donut.label

Logical value, whether to show total number in the center of the plot. Default: TRUE.

donut.label.size

The label size of center label. Default: 4.

donut.label.color

The color of center label. Default: red.

nudge_x

Parameter of geom_text_repel. Default: 1.

nudge_y

Parameter of geom_text_repel. Default: 1.

Value

A ggplot2 object.

Examples

library(ggpie)
library(ggplot2)
data(diamonds)
# circle label and out of pie
ggdonut(
  data = diamonds, group_key = "cut", count_type = "full",
  label_info = c("count", "ratio"), label_type = "circle",
  label_size = 4, label_pos = "out"
)
# circle label and in pie plot, with no split
ggdonut(
  data = diamonds, group_key = "cut", count_type = "full",
  label_info = c("count", "ratio"), label_type = "circle", label_split = NULL,
  label_size = 4, label_pos = "in"
)
# horizon label and in pie plot, with no split
ggdonut(
  data = diamonds, group_key = "cut", count_type = "full",
  label_info = c("count", "ratio"), label_type = "horizon", label_split = NULL,
  label_size = 4, label_pos = "in"
)
# horizon label and in pie plot
ggdonut(
  data = diamonds, group_key = "cut", count_type = "full",
  label_info = c("count", "ratio"), label_type = "horizon",
  label_size = 4, label_pos = "in"
)
# horizon label and out of pie plot, with no split
ggdonut(
  data = diamonds, group_key = "cut", count_type = "full",
  label_info = c("count", "ratio"), label_type = "horizon", label_split = NULL,
  label_size = 4, label_pos = "out"
)
# horizon label and out of pie plot
ggdonut(
  data = diamonds, group_key = "cut", count_type = "full",
  label_info = c("count", "ratio"), label_type = "horizon",
  label_size = 4, label_pos = "out"
)
# with label threshold
ggdonut(
  data = diamonds, group_key = "cut", count_type = "full",
  label_info = c("count", "ratio"), label_type = "horizon", label_split = NULL,
  label_size = 4, label_pos = "in", label_threshold = 10
)
ggdonut(
  data = diamonds, group_key = "cut", count_type = "full",
  label_info = c("count", "ratio"), label_type = "horizon",
  label_size = 4, label_pos = "in", label_threshold = 10
)

Create nested pie plot.

Description

Create nested pie plot.

Usage

ggnestedpie(
  data,
  group_key = NULL,
  count_type = c("count", "full"),
  r0 = 0.5,
  r1 = 1.5,
  r2 = 2.5,
  inner_thick = 1,
  outer_thick = 1,
  inner_fill_color = NULL,
  inner_label = TRUE,
  inner_label_info = c("count", "ratio", "all"),
  inner_label_color = "black",
  inner_label_split = "[[:space:]]+",
  inner_label_len = 40,
  inner_label_threshold = NULL,
  inner_label_size = 4,
  outer_fill_color = NULL,
  outer_label_type = c("circle", "horizon", "none"),
  outer_label_pos = c("in", "out"),
  outer_label_info = c("count", "ratio", "all"),
  outer_label_split = "[[:space:]]+",
  outer_label_len = 40,
  outer_label_color = "black",
  outer_label_gap = 0.05,
  outer_label_threshold = NULL,
  outer_label_size = 4,
  border_color = "black",
  border_size = 1,
  outer_nudge_x = 1,
  outer_nudge_y = 1
)

Arguments

data

Data frame contains full data or summarized data.

group_key

Column used to summarize the data. Default: NULL.

count_type

Data frame type, chosen from "count" and "full". "count" means summarized data and "full" means full data. Default: count.

r0

The radius of inner blank circle. Default: 0.5 (donut plot). When set to 0, inner plot is pie.

r1

The radius of inner pie plot. Default: 1.5.

r2

The radius of outer pie plot. Default: 2.5.

inner_thick

The width of inner pie plot. Default: 1.

outer_thick

The width of outer pie plot. Default: 1.

inner_fill_color

Colors used for inner pie plot. Default: NULL (conduct automatic selection).

inner_label

Logical value, whether to show label on inner pie label. Default: TRUE.

inner_label_info

Label information type of inner pie plot, chosen from count, ratio and all (count and ratio). Default: count.

inner_label_color

Color of the label on inner pie. Default: black.

inner_label_split

Pattern used to split the label of inner pie, support regular expression. Default: space.

inner_label_len

Label text length of inner pie. Used when inner_label_split is NULL. Default: 40.

inner_label_threshold

Threshold of the ratio to determine label or not on inner pie. Default: NULL.

inner_label_size

Size of the label on inner pie. Default: 4.

outer_fill_color

Colors used for outer pie plot. Default: NULL (conduct automatic selection).

outer_label_type

Label style of outer pie plot, chosen from circle, horizon and none (no label). Default: circle.

outer_label_pos

Label position of outer pie, chosen from in and out. Default: in.

outer_label_info

Label information type of outer pie plot, chosen from count, ratio and all (count and ratio). Default: count.

outer_label_split

Pattern used to split the label of outer pie, support regular expression. Default: space.

outer_label_len

Label text length of outer pie. Used when outer_label_split is NULL. Default: 40.

outer_label_color

Color of the label on outer pie. Default: black.

outer_label_gap

Gap between label and outer pie plot, used when outer_label_pos is out.

outer_label_threshold

Threshold of the ratio to determine label position (in/out pie). Default: NULL.

outer_label_size

Size of the label on outer pie. Default: 4.

border_color

Border color. Default: black.

border_size

Border thickness. Default: 1.

outer_nudge_x

Parameter of geom_text_repel. Default: 1.

outer_nudge_y

Parameter of geom_text_repel. Default: 1.

Value

A ggplot2 object.

Examples

library(ggpie)
library(ggplot2)
data(diamonds)
# inner circle label, outer circle label and in pie plot
ggnestedpie(
  data = diamonds, group_key = c("cut", "color"), count_type = "full",
  inner_label_info = "all", inner_label_split = NULL,
  outer_label_type = "circle", outer_label_pos = "in", outer_label_info = "all"
)
# inner circle label, outer circle label and in pie plot, remove fraction below 1 of inner pie
ggnestedpie(
  data = diamonds, group_key = c("cut", "color"), count_type = "full",
  inner_label_info = "all", inner_label_split = NULL,
  inner_label_threshold = 1, inner_label_size = 3,
  outer_label_type = "circle", outer_label_pos = "in", outer_label_info = "all"
)
# inner circle label, outer circle label and out of pie plot
ggnestedpie(
  data = diamonds, group_key = c("cut", "color"), count_type = "full",
  inner_label_info = "all", inner_label_split = NULL,
  outer_label_type = "circle", outer_label_pos = "out", outer_label_info = "all"
)
# inner circle label and no split, outer horizon label and out of pie plot,
# remove fraction below 1 of inner pie
ggnestedpie(
  data = diamonds, group_key = c("cut", "color"), count_type = "full",
  inner_label_info = "all", inner_label_split = NULL,
  inner_label_threshold = 1, inner_label_size = 3,
  outer_label_type = "horizon", outer_label_pos = "out", outer_label_info = "all"
)
# inner circle label and no split, outer horizon label and in pie plot,
# remove fraction below 1 of inner pie,
# adjust fraction below 10 to out of pie of outer pie plot.
ggnestedpie(
  data = diamonds, group_key = c("cut", "color"), count_type = "full",
  inner_label_info = "all", inner_label_split = NULL,
  inner_label_threshold = 1, inner_label_size = 3,
  outer_label_type = "horizon", outer_label_pos = "in",
  outer_label_info = "all", outer_label_threshold = 10
)
# create blank between inner and outer pie
ggnestedpie(
  data = diamonds, group_key = c("cut", "color"), count_type = "full", r0 = 0.5, r1 = 1.5, r2 = 2.6,
  inner_label_info = "all", inner_label_split = NULL,
  inner_label_threshold = 1, inner_label_size = 3,
  outer_label_type = "horizon", outer_label_pos = "in",
  outer_label_info = "all", outer_label_threshold = 10
)

Create Pie plot.

Description

Create Pie plot.

Usage

ggpie(
  data,
  group_key = NULL,
  count_type = c("count", "full"),
  fill_color = NULL,
  label_info = "count",
  label_split = "[[:space:]]+",
  label_len = 40,
  label_color = "black",
  label_type = c("circle", "horizon", "none"),
  label_pos = c("in", "out"),
  label_gap = 0.05,
  label_threshold = NULL,
  label_size = 4,
  border_color = "black",
  border_size = 1,
  nudge_x = 1,
  nudge_y = 1
)

Arguments

data

Data frame contains full data or summarized data.

group_key

Column used to summarize the data. Default: NULL.

count_type

Data frame type, chosen from "count" and "full". "count" means summarized data and "full" means full data. Default: count.

fill_color

Colors used. Default: NULL (conduct automatic selection).

label_info

Label information type, combine from group, count, ratio. For example, use "count" , "ratio" will show count and ratio, count is main label info, ratio is in brackets. Default: count.

label_split

Pattern used to split the label, support regular expression. Default: space.

label_len

The length of label text. Used when label_split is NULL. Default: 40.

label_color

Color of the label. Default: black.

label_type

Label style, chosen from circle, horizon and none (no label). Default: circle.

label_pos

Label position, chosen from in and out. Default: in.

label_gap

Gap between label and pie plot, used when label_pos is out.

label_threshold

Threshold of the ratio to determine label position (in/out pie). Default: NULL.

label_size

Size of the label. Default: 4.

border_color

Border color. Default: black.

border_size

Border thickness. Default: 1.

nudge_x

Parameter of geom_text_repel. Default: 1.

nudge_y

Parameter of geom_text_repel. Default: 1.

Value

A ggplot2 object.

Examples

library(ggpie)
library(ggplot2)
data(diamonds)
# with no label
ggpie(
  data = diamonds, group_key = "cut", count_type = "full",
  label_info = c("count", "ratio"), label_type = "none"
)
# circle label and out of pie
ggpie(
  data = diamonds, group_key = "cut", count_type = "full",
  label_info = c("count", "ratio"), label_type = "circle",
  label_size = 4, label_pos = "out"
)
# circle label and in pie plot, with no split
ggpie(
  data = diamonds, group_key = "cut", count_type = "full",
  label_info = c("count", "ratio"), label_type = "circle", label_split = NULL,
  label_size = 4, label_pos = "in"
)
# horizon label and in pie plot, with no split
ggpie(
  data = diamonds, group_key = "cut", count_type = "full",
  label_info = c("count", "ratio"), label_type = "horizon", label_split = NULL,
  label_size = 4, label_pos = "in"
)
# horizon label and in pie plot, split with space
ggpie(
  data = diamonds, group_key = "cut", count_type = "full",
  label_info = c("count", "ratio"), label_type = "horizon",
  label_size = 4, label_pos = "in"
)
# horizon label and out pie plot, with no split
ggpie(
  data = diamonds, group_key = "cut", count_type = "full",
  label_info = c("count", "ratio"), label_type = "horizon", label_split = NULL,
  label_size = 4, label_pos = "out"
)
# with label threshold
ggpie(
  data = diamonds, group_key = "cut", count_type = "full",
  label_info = c("count", "ratio"), label_type = "horizon", label_split = NULL,
  label_size = 4, label_pos = "in", label_threshold = 10
)

Create 3D pie plot.

Description

Create 3D pie plot.

Usage

ggpie3D(
  data,
  group_key = NULL,
  count_type = c("count", "full"),
  fill_color = NULL,
  start_degrees = 0,
  tilt_degrees = -20,
  height = 0.1,
  darken = 0.15,
  camera_eye = c(0, 3, 5),
  camera_look_at = c(0, 0, 0),
  show_label = TRUE,
  label_info = "count",
  label_split = "[[:space:]]+",
  label_len = 40,
  label_size = 4
)

Arguments

data

Data frame contains full data or summarized data.

group_key

Column used to summarize the data. Default: NULL.

count_type

Data frame type, chosen from "count" and "full". "count" means summarized data and "full" means full data. Default: count.

fill_color

Colors used. Default: NULL (conduct automatic selection).

start_degrees

starting angle for first pie slice (in degrees). Default: 0.

tilt_degrees

angle by which to tilt the pie towards the camera (in degrees). Default: 0.

height

height of the pie. Default: 0.1.

darken

Shadow degree. Default: 0.15.

camera_eye

location of camera eye. Default: c(0, 3, 5).

camera_look_at

at what point is the camera looking. Default: c(0, 0, 0).

show_label

Logical value, whether to show label or not. Default: TRUE.

label_info

Label information type, combine from group, count, ratio. For example, use "count" , "ratio" will show count and ratio, count is main label info, ratio is in brackets. Default: count.

label_split

Pattern used to split the label, support regular expression. Default: space.

label_len

The length of label text. Used when label_split is NULL. Default: 40.

label_size

Size of the label. Default: 4.

Value

A ggplot2 object.

Examples

library(ggpie)
library(ggplot2)
data(diamonds)
ggpie3D(data = diamonds, group_key = "cut", count_type = "full", tilt_degrees = -10)
ggpie3D(
  data = mtcars, group_key = "cyl", count_type = "full",
  tilt_degrees = -10, start_degrees = 0, label_info = c("count", "ratio")
)
data <- data.frame(group = letters[1:5], count = c(1, 2, 3, 1, 1), stringsAsFactors = FALSE)
ggpie3D(data = data, start_degrees = 0, label_split = NULL, label_info = c("count", "ratio"))

Create rose pie plot.

Description

Create rose pie plot.

Usage

ggrosepie(
  data,
  group_key = NULL,
  count_type = c("count", "full"),
  fill_color = NULL,
  label_info = c("count", "ratio", "all"),
  label_split = NULL,
  label_len = 40,
  label_color = "black",
  sort = TRUE,
  show_tick = TRUE,
  tick_break = NULL,
  show_label = TRUE,
  label_sep = "|",
  label_gap = 0.05,
  label_size = 4,
  donut_frac = 0.1,
  donut_label = TRUE,
  donut_label_size = 4,
  donut_label_color = "red",
  border_color = "black",
  border_size = 1
)

Arguments

data

Data frame contains full data or summarized data.

group_key

Column used to summarize the data, one or two are acceptable. Default: NULL.

count_type

Data frame type, chosen from "count" and "full". "count" means summarized data and "full" means full data. Default: count.

fill_color

Colors used. When length of group_key is two, color the subgroup, otherwise the main group. Default: NULL (conduct automatic selection).

label_info

Label information type of outer pie plot, chosen from count, ratio and all (count and ratio). Default: count.

label_split

Pattern used to split the label, support regular expression. Default: NULL.

label_len

The length of label text. Used when label_split is NULL. Default: 40.

label_color

Color of the label. When length of group_key is two, this should be set to one color. Default: black.

sort

Logical value, whether to order the plot by counts. Default: TRUE.

show_tick

Logical value, whether to show the tick. Default: TRUE.

tick_break

The break of tick. Default: NULL (conduct automatic selection).

show_label

Logical value, whether to show the label. Default: TRUE.

label_sep

The separator between group and count info. Default: |.

label_gap

The gap between label and plot. Default: 0.05 (count + 0.05*count).

label_size

The size of label. Default: 4.

donut_frac

The fraction of donut. Default: 0.1 (0.1*max(count)).

donut_label

Logical value, whether to show total number in the center of the plot. Default: TRUE.

donut_label_size

The label size of center label. Default: 4.

donut_label_color

The color of center label. Default: red.

border_color

Border color. Default: black.

border_size

Border thickness. Default: 1.

Value

A ggplot2 object.

Examples

library(ggpie)
library(ggplot2)
data(diamonds)
# do not show tick
ggrosepie(diamonds,
  group_key = "color", count_type = "full", label_info = "all",
  show_tick = FALSE, donut_frac = 0.3, donut_label_size = 3
)
# show tick and with automatic selection
ggrosepie(diamonds,
  group_key = "color", count_type = "full", label_info = "all",
  donut_frac = 0.3, donut_label_size = 3
)
# show tick and with specific break
ggrosepie(diamonds,
  group_key = "color", count_type = "full", label_info = "all",
  tick_break = c(3000, 5000, 7000, 11000), donut_frac = 0.3, donut_label_size = 3
)
# two group variable, and do not show tick
ggrosepie(diamonds,
  group_key = c("color", "clarity"),
  count_type = "full", label_info = "all",
  show_tick = FALSE, donut_frac = 0.3, donut_label_size = 3
)
# two group variable, show tick and with automatic selection
ggrosepie(diamonds,
  group_key = c("color", "clarity"),
  count_type = "full", label_info = "all",
  donut_frac = 0.3, donut_label_size = 3
)
# two group variable, show tick and with specific break
ggrosepie(diamonds,
  group_key = c("color", "clarity"),
  count_type = "full", label_info = "all",
  tick_break = c(3000, 5000, 7000, 11000), donut_frac = 0.3, donut_label_size = 3
)