Package 'tastypie'

Title: Easy Pie Charts
Description: You only need to type 'why pie charts are bad' on Google to find thousands of articles full of (valid) reasons why other types of charts should be preferred over this one. Therefore, because of the little use due to the reasons already mentioned, making pie charts (and related) in R is not straightforward, so other functions are needed to simplify things. In this R package there are useful functions to make 'tasty' pie charts immediately by exploiting the many cool templates provided.
Authors: Paolo Dalena [aut, cre]
Maintainer: Paolo Dalena <[email protected]>
License: GPL-3
Version: 0.1.1
Built: 2025-02-28 03:01:44 UTC
Source: https://github.com/paolodalena/tastypie

Help Index


Easily create circular packing charts

Description

This function allows you to create cool circular packing charts easily by providing just the data and a template among the available ones. Moreover, you can choose whether and where to display percentages and also optionally specify a title for the chart.

Usage

bubble_blow(data, template, perc = "no", title = "")

Arguments

data

A data frame (or a tibble) with two variables (columns):

  • in the first one there must be the vector of labels;

  • in the second one there must be the vector of values.
    You can use pie_datacheck to understand if the data is suitable.

template

The chosen template.
The available templates for this function are 'bub1', 'bub2', 'bub3', 'bub4', 'bub5'.

perc

You can choose among:

  • 'no' : the percentages won't be displayed (default choice);

  • 'below' : the percentages will be displayed below the group labels;

  • 'right' : the percentages will be displayed next to the group labels.

title

A string. If you want, you can specify the title of the graph.

Value

A ggplot object. In particular, this function returns a circular packing chart according to the data, the choice of the template, and the other specifications provided.

See Also

See all the available templates displayed here!

Examples

example <- data.frame(
  c("This", "Is", "Just", "An", "Example"),
  c(2.9, 6.9, 4.20, 13.12, 6.66)
)
bubble_blow(
  data = example,
  template = "bub1",
  perc = "below",
  title = "Example1"
)

example2 <- tibble::tibble(
  c("cat 1", "cat2", "cat3", "cat4", "cat5", "cat6", "cat7", "cat8", "cat9"),
  c(324, 432, 499, 291, 750, 836, 314, 133, 372)
)
bubble_blow(
  data = example2,
  template = "bub2",
  perc = "right",
  title = "Ex2"
)

Add images to pie charts

Description

This function allows to easily add some figures to you pie chart, taking information from the output of the pie_bake function. You can also customize the chart by specifying the colors of borders and labels, the title of the pie chart and where (and if) you want to print the percentages for each group.

Usage

pie_addimages(
  mypie,
  imglist,
  perc = "no",
  lbl_col = "black",
  border_col = "black",
  title = ""
)

Arguments

mypie

A ggplot object. The output from pie_bake, NOT from pie_bake_pro.
Don't focus on the template, only labels and values will be inherited.

imglist

A list of objects returned by and readJPEG used to fill slices. For optimal and fast results, we recommend the use of small files (5-10 kB).

perc

You can choose among:

  • 'no' : the percentages won't be displayed (default choice);

  • 'below' : the percentages will be displayed below the group labels;

  • 'right' : the percentages will be displayed next to the group labels.

lbl_col

A string containing the chosen color for the labels, default is "black".

border_col

A string containing the chosen color for the border of the pie chart, default is "black".

title

A string. If you want, you can specify the title of the graph.

Value

A ggplot object.

See Also

Please note that this function is based on the imagepie function.

Examples

img5 <- jpeg::readJPEG(system.file("img", "pie.jpeg", package = "tastypie"))
imgs2 <- list(img5, img5, img5)

df2 <- data.frame(
  c("A", "B", "C"),
  c(300, 250, 600)
)

mypie2 <- pie_bake(df2, template = "rainbow1")

pie_addimages(
  mypie = mypie2,
  imglist = imgs2,
  perc = "right",
  lbl_col = "darkcyan",
  border_col = "orangered",
  title = "Example"
)

Easily create pie charts

Description

This function allows you to create cool pie charts easily by providing just the data and a template among the available ones. Moreover, you can choose whether to display percentages or not and also optionally specify a title for the chart and a name for the categories.

Using this function you can create the classical pie charts (including the donut charts). If you are looking for something more complex and extravagant (but probably less understandable), check out the pie_bake_pro function.

Usage

pie_bake(data, template, perc = FALSE, group_name = "group", title = "")

Arguments

data

A data frame (or a tibble) with two variables (columns):

  • in the first one there must be the vector of labels;

  • in the second one there must be the vector of values.

Please note that the labels are automatically sorted in alphabetical order. If you want to specify a particular order, it is recommended to type numbers or letters before the category names (e.g. "a. category1", "b. category2", ...).
You can use pie_datacheck to understand if the data is suitable.

template

The chosen template.
Type pie_template_list to display all the available ones for this function.

perc

A logical value. Should the proportions be displayed?

group_name

A string. If you want, you can specify a name for the categories.

title

A string. If you want, you can specify the title of the graph.

Value

A ggplot object. In particular, this function returns a pie (or donut) chart according to the data, the choice of template, and the other specifications provided.

See Also

See all the available templates displayed here!

Examples

example <- data.frame(
  c("a. This", "b. Is", "c. Just", "d. An", "e. Example"),
  c(2.9, 6.9, 4.20, 13.12, 6.66)
)
pie_bake(
  data = example,
  template = "basic3",
  perc = TRUE,
  group_name = "groups",
  title = "Example1"
)

pie_bake(
  data = example,
  template = "red1",
   title = "Ex2"
)

pie_bake(
  data = example,
  template = "donut2",
  perc = TRUE,
  group_name = "CAT:"
)

Easily create (more complex) pie charts

Description

This function allows you to create cool pie charts easily by providing just the data and a template among the available ones. Moreover, you can optionally specify a title for the chart and a name for the categories.

Using this function you can create some complex and extravagant pie charts. If you are looking for something more classical (and probably more understandable), check out the pie_bake function.

Usage

pie_bake_pro(data, template, group_name = "group", title = "")

Arguments

data

A data frame (or a tibble) with two variables (columns):

  • in the first one there must be the vector of labels;

  • in the second one there must be the vector of values.

Please note that the labels are automatically sorted in alphabetical order. If you want to specify a particular order, it is recommended to type numbers or letters before the category names (e.g. "a. category1", "b. category2", ...).
You can use pie_datacheck to understand if the data is suitable.

template

The chosen template.
Type pie_template_list_pro to display all the available ones for this function.

group_name

A string. If you want, you can specify a name for the categories.

title

A string. If you want, you can specify the title of the graph.

Value

A ggplot object (or no value if the chosen template is among the spider chart ones). In particular, this function returns a pie (or similar) chart according to the data, the choice of template, and the other specifications provided.

See Also

See all the available templates displayed here!

Examples

example <- data.frame(
  c("a. This", "b. Is", "c. Just", "d. An", "e. Example"),
  c(2.9, 6.9, 4.20, 13.12, 6.66)
)
pie_bake_pro(
  data = example,
  template = "eaten3",
  group_name = "cat:",
  title = "Example1"
)

pie_bake_pro(
  data = example,
  template = "dart1",
  title = "Example2!"
)

pie_bake_pro(
  data = example,
  template = "eye5",
  group_name = "GROUPS:"
)

pie_bake_pro(
  data = example,
  template = "spider2"
  )

Check if the data is good for making tasty pies

Description

pie_datacheck checks if the provided data are suitable for creating pie charts using the useful functions in the tastypie package.

Usage

pie_datacheck(data, check = FALSE)

Arguments

data

The data that you want to use for creating pie charts.

check

Logical, set equal to TRUE if you need a message to know if there are no problems.

Value

If the provided data are a dataframe with only two variables (columns) with the vector of labels in the first one and the vector of values in the second one, nothing will happen. Otherwise, an error that tells you what's wrong occurs.

Examples

wrong <- c(1, 2, 3)
# Would return an Error

wrong2 <- data.frame("a" = c(1, 2, 3), "b" = c("ex", "am", "ple"))
# Would return an Error

right <- data.frame("a" = c("ex", "am", "ple"), "b" = c(1, 2, 3))
pie_datacheck(right) # No Error ==> OK!
pie_datacheck(right, check = TRUE) # Positive message

Discover templates for tastypie

Description

This function allows to user to find out a random combination of templates, number of groups and features in order to get an idea of the many available plots in the package tastypie.

Usage

pie_discover(which = c("all", "bake", "pro"))

Arguments

which

Allows to select a subset of the available templates.

If "all", the template is randomly chosen among all the available ones.
If "bake", the template is randomly chosen among the ones that can be used through pie_bake.
If "pro", the template is randomly chosen among the (more complex) ones that can be used through pie_bake_pro.

The default value is "all".

Value

A ggplot object. In particular, this function returns a pie (or similar) chart according to a random choice of template and the other features.

See Also

See all the available templates displayed here!

Examples

pie_discover()
pie_discover("pro")

Available templates in tastypie for pie_bake.

Description

The vector containing all the available templates for pie charts for the pie_bake function. Other more complex templates are available in pie_template_list_pro that can be used through the pie_bake_pro function.

Usage

pie_template_list

Format

An object of class character of length 30.

See Also

See all the available templates displayed here!


Available templates in tastypie for pie_bake_pro.

Description

The vector containing all the available templates for pie charts for the pie_bake_pro function. Other less complex templates are available in pie_template_list that can be used through the pie_bake function.

Usage

pie_template_list_pro

Format

An object of class character of length 30.

See Also

See all the available templates displayed here!


Display an example of a particular template

Description

This function allows to user to display a pie chart by selecting the template, the number of groups of interest and whether to display the proportions or not, in order to make it easier to choose between the many templates available in the package tastypie.

Usage

pie_templates(template, n_groups = 4, perc = FALSE)

Arguments

template

The chosen template.

n_groups

A number from 2 to 9.

perc

A logical value. Should the proportions be displayed?
Note that if the selected template is one of those to be used with pie_bake_pro (listed in the pie_template_list_pro vector), this argument is useless.

Value

A ggplot object. In particular, this function returns a pie (or similar) chart according to the choice of template and the other specifications provided.

See Also

See all the available templates displayed here!

Examples

pie_templates(template = "bw1", n_groups = 3, perc = TRUE)
pie_templates(template = "watermelon2", n_groups = 8)

Easy pie charts with tastypie

Description

You only need to type why pie charts are bad on Google to find thousands of articles full of (valid) reasons why other types of charts should be preferred over this one.
Therefore, because of the little use due to the reasons already mentioned, making pie charts (and related) in R is not straightforward, so other functions are needed to simplify things.
In this R package there are useful functions to make tasty pie charts immediately by exploiting the many cool templates provided.

Author(s)

Author and Maintainer: Paolo Dalena [email protected]

See Also

Find more information on the package web site here, or on the GitHub package page here.