Graph the Distribution of a Variable

Learn how to graph the distribution of a variable using R.

Visualization with R

An important part of data analysis is visualizing the distribution of a variable of interest. We illustrate this by using R functions to graph the distribution of the v1 variable in the vd dataset. How we graph vd$v1 depends on what type of variable we think it is either discrete or continuous. A discrete variable only takes on a finite number of values, such as gender, age, and the number of children in a household. In contrast, a continuous variable takes on an infinite number of possible values, even within a range, like weight, distance, and income. If we treat v1 as a discrete variable, we can use a frequency table and bar chart to demonstrate its distribution.

A frequency table displays data values of a variable and how often each value occurs. It’s often first used to examine the distribution of a discrete variable. In R, the table() function computes the frequency count for each variable value. The R code and output are as follows:

Get hands-on with 1200+ tech skills courses.