Pie chart with facet_wrap in R
In general, Facetting is the process that refers to the split of the output chart(plot) window as grids to display similar charts under the same section. This can be achieved for the plots which are plotted using the ggplot2 package in R Programming Language.
Syntax: facet_wrap(facets, nrow, ncol, scales, shrink, dir, strip.position)
- facets – the set of grouped variables(data table)
- nrow, ncol – to specify the number of rows and columns respectively
- scales – the scales should be fixed or free is specified here
- shrink – If TRUE, will shrink scales to fit output of statistics
- dir – Used to specify direction of plot (“h” for horizontal or “v”, for vertical.)
- strip.position – Used to specify the position of labels
Steps to Plot Pie Chart With facet_wrap()
Install and load the required package.
Creation of sample data frame with groups and sub-groups and converting it to data table as follows.
Basic Pie plot using ggplot2 package for our data frame.
In this example, we are facetting pie chart based on branches of students as follows using the facet_wrap() function
My Personal Notes arrow_drop_up
Please Login to comment...