Many graphical representations in R Language are available for both qualitative and quantitative data types. In this post, we will only discuss graphical representations in R such as histograms, bar plots, and box plots.

## Table of Contents

### Creating Histogram in R

To visualize a single variable, the histogram can be drawn using the `hist()`

function in R. The use of histograms is to judge the shape and distribution of data in a graphical way. Histograms are also used to check the normality of the variable.

Let us attach the data from `iris`

dataset.

attach(iris) head(iris) hist(Petal.Width)

We can enhance the histogram by using some arguments/parameters related to the `hist()`

function in R. For example,

hist(Petal.Width, xlab = "Petal Width", ylab = "Frequency", main = "Histogram of Petal Width from Iris Data set", breaks = 10, col = "dodgerblue", border = "orange")

### Creating Barplots in R

The bar plots are the best choice for visual inspection of a categorical variable (or a numeric variable with a finite number of values), or a rank variable. Usually, one can use bar plots for comparison purposes. The `barplot()`

function can be used for visual inspection of a categorical variable.

library(mtcars) barplot( table(cyl) )

barplot(table(cyl), ylab = "Frequency", xlab = "Cylinders (4, 6, 8)", main = "Number of cylinders ", col = "green", border = "blue")

### Creating Boxplots in R

One can use Boxplots to visualize the normality, skewness, and existence of outliers in the data based on five-number summary statistics.

boxplot(mpg) boxplot(Petal.Width) boxplot(Petal.Length)

However, one can compare a numerical variable for different values of a categorical/grouping variable. For example,

boxplot(mpg ~ cyl, data = mtcars)

The reads the formula `mpg ~ cyl`

as: “Plot the `mpg`

variable against the `cyl`

variable using the dataset `mtcars`

. The symbol `~`

used to specify a formula in R.

boxplot(mpg ~ cyl, data =mtcars, xlab = "Cylinders", ylab = "Miles per Gallon", pch = 20, cex = 2, col = "pink", border = "black")

See How to perform descriptive statistics

Visit: MCQs and Quiz site https://gmstat.com