Create Boxplots by Group of categorical data
In this method to create the boxplot by a group of the given categorical data, the user needs to install and import the ggplot2 package to provide its functionalities and then the user simply needs to call the geom_box() function with the given data to plot a ggplot2 boxplot by the group in the R programming language.
Syntax:
geom_box()
Example: Plotting boxplot of categorical data
R
library (ggplot2) data < - data.frame (x= c ( 'M' , 'F' , 'M' , 'F' , 'M' , 'F' , 'M' , 'F' , 'M' , 'F' , 'M' , 'F' , 'M' , 'M' , 'M' ), y= c ( 'B' , 'G' , 'B' , 'B' , 'G' , 'G' , 'B' , 'G' , 'G' , 'B' , 'G' , 'G' , 'B' , 'G' , 'G' ), a= c (8, 6, 6, 1, 2, 3, 7, 4, 4, 2, 5, 8, 1, 3, 2), b= c (5, 7, 7, 4, 5, 6, 7, 8, 8, 6, 9, 4, 1, 8, 1)) ggplot (data, aes (x, y=a)) + geom_boxplot () |
Output:
How to Plot Categorical Data in R?
In this article, we will be looking at different plots for the categorical data in the R programming language.
Categorical Data is a variable that can take on one of a limited, and usually fixed, a number of possible values, assigning each individual or other unit of observation to a particular group or nominal category on the basis of some qualitative property.