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 |
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.
bubble_blow(data, template, perc = "no", title = "")
bubble_blow(data, template, perc = "no", title = "")
data |
A data frame (or a tibble) with two variables (columns):
|
template |
The chosen template. |
perc |
You can choose among:
|
title |
A string. If you want, you can specify the title of the graph. |
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 all the available templates displayed here!
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" )
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" )
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.
pie_addimages( mypie, imglist, perc = "no", lbl_col = "black", border_col = "black", title = "" )
pie_addimages( mypie, imglist, perc = "no", lbl_col = "black", border_col = "black", title = "" )
mypie |
A ggplot object. The output from |
imglist |
A list of objects returned by and |
perc |
You can choose among:
|
lbl_col |
A string containing the chosen color for the labels, default is
|
border_col |
A string containing the chosen color for the border of the pie
chart, default is |
title |
A string. If you want, you can specify the title of the graph. |
A ggplot object.
Please note that this function is based on the imagepie
function.
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" )
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" )
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.
pie_bake(data, template, perc = FALSE, group_name = "group", title = "")
pie_bake(data, template, perc = FALSE, group_name = "group", title = "")
data |
A data frame (or a tibble) with two variables (columns):
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", ...). |
template |
The chosen template. |
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. |
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 all the available templates displayed here!
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:" )
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:" )
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.
pie_bake_pro(data, template, group_name = "group", title = "")
pie_bake_pro(data, template, group_name = "group", title = "")
data |
A data frame (or a tibble) with two variables (columns):
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", ...). |
template |
The chosen template. |
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. |
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 all the available templates displayed here!
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" )
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" )
pie_datacheck
checks if the provided data are suitable for creating pie charts
using the useful functions in the tastypie
package.
pie_datacheck(data, check = FALSE)
pie_datacheck(data, check = FALSE)
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. |
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.
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
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
tastypie
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
.
pie_discover(which = c("all", "bake", "pro"))
pie_discover(which = c("all", "bake", "pro"))
which |
Allows to select a subset of the available templates. |
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 all the available templates displayed here!
pie_discover() pie_discover("pro")
pie_discover() pie_discover("pro")
tastypie
for pie_bake
.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.
pie_template_list
pie_template_list
An object of class character
of length 30.
See all the available templates displayed here!
tastypie
for pie_bake_pro
.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.
pie_template_list_pro
pie_template_list_pro
An object of class character
of length 30.
See all the available templates displayed here!
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
.
pie_templates(template, n_groups = 4, perc = FALSE)
pie_templates(template, n_groups = 4, perc = FALSE)
template |
The chosen template. |
n_groups |
A number from 2 to 9. |
perc |
A logical value. Should the proportions be displayed? |
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 all the available templates displayed here!
pie_templates(template = "bw1", n_groups = 3, perc = TRUE) pie_templates(template = "watermelon2", n_groups = 8)
pie_templates(template = "bw1", n_groups = 3, perc = TRUE) pie_templates(template = "watermelon2", n_groups = 8)
tastypie
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 and Maintainer: Paolo Dalena [email protected]
Find more information on the package web site here, or on the GitHub package page here.