Create Horizontal boxplot in base R

In this method to create the horizontal bar plot, the user simply needs to call the boxplot() function which is a base function of the R language, then the user needs to call the horizontal argument of this function and initialize it with true value to get the box plot in a horizontal way.

boxplot() function: This function is used to produce box-and-whisker plot(s) of the given values.

Syntax: boxplot(formula, data = NULL, …, horizontal = TRUE)

Parameters:

  • formula: a formula, such as y ~ grp, where y is a numeric vector of data values to be split into groups according to the grouping variable grp.
  • data: a data.frame (or list) from which the variables in the formula should be taken.
  • horizontal: logical indicating if the boxplots should be horizontal.
  • … : Other parameters

Example: In this example, we are taking a data frame with 2 variables to create the horizontal boxplot of the given variable using the boxplot with a horizontal argument with it in the R programming language.

R




# Create DataFrame
gfg<-data.frame(x=c(6,8,9,6,4,7,6,3,4),
                y=c(4,6,8,7,8,4,5,1,3))
  
# Create Horizontal Boxplot
boxplot(gfg,horizontal=TRUE)


Output:

How to Create Horizontal Boxplots in R?

In this article, we will discuss how to create horizontal boxplots in the R programming language.

Similar Reads

Method 1: Create Horizontal boxplot in base R

In this method to create the horizontal bar plot, the user simply needs to call the boxplot() function which is a base function of the R language, then the user needs to call the horizontal argument of this function and initialize it with true value to get the box plot in a horizontal way....

Method 2: Create a Horizontal boxplot using coord_flip()

...

Contact Us