For a general presentation of using R
and lessR
, including examples of bar charts, access the following sources.
R
session, enter browseVignettes("lessR")
, then select the Bar Chart, Pie Chart
vignetteR
session, enter ?BarChart
to access the manual that describes the BarChart()
function
A categorical variable has a relatively small number of unique values, called levels. For example, on a survey form, Gender can be assessed with three levels: Male, Female, and Other. Or, these values can be represented as integers: 1, 2, and 3. Wether the values are of type character
, the R variable type for a categorical variable, type factor
, or type integer
, the corresponding variable Gender is categorical.
The bar chart associates a number with each level of a categorical variable. A bar chart is constructed from this table with two columns, one column a level of the categorical variable and the second column the associated number. The chart consists of a bar for each level with a height proportional to that associated number. In general, the associated number can be any value but usually is the result of a statistical calculation.
There are three possibilities for the source of the number associated with each level or category of the categorical variable of interest.
Probably the most common type of bar chart calculates the number associated with each level as the count of the number of values for the corresponding level of the categorical variable. This bar chart answers the question: How often did the values of each level of the categorical variable occur in the data? For example, how many students in the classroom term for homework assignment in on time, and how many turned in the assignment late? The only needed information for which to compute this type of bar chart are the values of the categorical variable.
The number associated with each category or level of a categorical variable can also be computed as a statistic from the analysis of a numerical variable at each level or category. For example, calculate the average salary for for the people each department of a company, such as accounting, sales, etc.
The possibility of reading a numerical variable also allows for the possibility reading the summary table from which the bar chart is constructed as the data for the analysis. As discussed, every bar chart is constructed from a summary table that associates each level of the categorical terrible with a number. Usually that number is calculated as either the counted values of a categorical variable for each level, or the calculation of a statistic for a numerical variable. Or, just enter that summary table directly as the given data, select the categorical variable, then select the corresponding numerical variable. This way the numerical variable can be anything at all, including constructing a bar chart for a published table without having access to the original data.
The two variable bar chart visualizes the relationship between two categorical variables. The corresponding cross-tabulation table shows that same relationship in tabular form from which the bar chart visualization is derived.
lessR
do permit more sensitivity to differentiate among objects with various types of color blindness: Okabe-Ito
and viridis
. These are qualitative palettes, which means that the hue varies across the plotted objects, here bars. Specify these, or other palettes, as the value for the fill
parameter, available both by entering a function call in the R console or via the interactive analysis.
For the full list of BarChart()
parameters, see the manual obtained by entering ?BarChart
. These listed parameters are those provided in the interactive session from interact("BarChart")
.
x
-variableby
-variableby
-variableby
-variable within the corresponding level of the x
-variable