R Func Boxplot
# R boxplot() Function - Drawing Box Plots
[ R Language Examples](https://example.com/r/r-examples.html)
The R boxplot() function is used to draw box plots, displaying the distribution characteristics and outliers of data.
A box plot displays the five-number summary of the data (minimum, Q1, median, Q3, maximum) as well as outliers.
The syntax format for the boxplot() function is as follows:
boxplot(x, horizontal = FALSE, col = NULL, main = "", xlab = "", ylab = "")
**Parameter Description:**
* **x** Numeric vector or formula (e.g., numeric ~ group).
## Example
# Score data for multiple classes
class_a <-c(78, 82, 85, 88, 90, 75, 80, 86, 92, 84)
class_b <-c(72, 75, 78, 76, 80, 70, 74, 77, 79, 73)
class_c <-c(85, 88, 90, 92, 95, 80, 87, 89, 91, 86)
# Draw box plot
boxplot(class_a, class_b, class_c,
names=c("Class A", "Class B", "Class C"),
main ="Score Distribution Comparison by Class",
xlab ="Class",
ylab ="Score",
col=c("skyblue", "lightgreen", "coral"))
Executing the above code will display a box plot comparison of scores for the three classes.
The boxplot() function is more friendly to grouped data using the formula form:
## Example
# Using formula form
scores <-c(class_a, class_b, class_c)
groups <-rep(c("Class A", "Class B", "Class C"), each =10)
boxplot(scores ~ groups,
YouTip