create a boxplot in r

Boxplots are used to display distribution of a numeric variable, showing the median, quartiles, outliers and range of the data.

We can create a boxplot in R using the boxplot() function. Here is an example:

main.r
# create a vector of random values
x <- rnorm(100)

# create a boxplot
boxplot(x)
82 chars
6 lines

This will create a simple boxplot of the x variable. We can also add more options to customize the plot, such as adding a title, changing the colors, adding labels to the axis, and so on.

Here is an example of a more customized boxplot:

main.r
# create a boxplot of the iris dataset
boxplot(Sepal.Width ~ Species, data = iris, 
        main = "Boxplot of Sepal Width by Species", 
        xlab = "Species", ylab = "Sepal Width",
        col = c("skyblue", "pink", "lightgreen"),
        notch = TRUE)
257 chars
7 lines

This creates a boxplot of the Sepal.Width variable of the iris dataset, grouped by Species. We added a title, labels to the axis, we changed the colors, and enabled the notch option to display a confidence interval around the median.

related categories

gistlibby LogSnag