4. Categorical variables
Key iNZight skills addressed:•••

Visual displays (Bar and Pareto charts) and summary tables for each categorical variable.
Colouring the bars.
Re-ordering the responses (and hence bars) based on their frequency.

Relevant StatsTuneUp video to consider:••‘Random Variables’ available at http://statstuneup.com.au/random-variables/‘Visual Displays: Single Variable’ available at http://statstuneup.com.au/one-variable/
Side note: Types of categorical variables
There are two types of categorical variables: ordinal and nominal variables.
The variable type determines how you display the data.
Recommended viewing: please consider the 4-minute animated videos ‘Random Variables’ and‘Visual Displays: Single Variable’ available at http://statstuneup.com.au/random-variables/ andhttp://statstuneup.com.au/one-variable/ (click on ‘The Video’ tab to view)
Ordinal Variables
When there is a natural ordering or hierarchy of the possible responses or categories (e.g., thevariable ‘Risk’ having possible responses of Low, Low-Medium, Medium, Medium-High, High) wehave an ordinal variable. It is important to keep this order when you present your datagraphically, or in a table showing the frequencies of each categorical response. Such a graph isreferred to as a bar chart.
Nominal Variables
When there is no natural ordering or hierarchy to the possible responses or categories (e.g., thevariable ‘eye colour’ having possible responses of brown, grey, green, blue, etc) we have anominal variable. When we present such a variable in a graph, or in a table showing thefrequencies of each categorical responses, there is no particular order for the categories wemust retain. The categorical responses may be arranged in descending order of frequency forexample. Such a graph is referred to as a Pareto chart.

INSTRUCTIONS
Load the nhanes_1000 dataset into iNZight using File > Example data …. You will find the data set
in Module (package) FutureLearn. See earlier worksheets if unfamiliar with this step.

Displaying Categorical Variables in iNZightPage 1 of 6

Creating bar charts of categorical variables•Drag the variable name Race3 into theVariable1 slot.

•Click Get Summary to obtain the associatedsummary table of counts and percentages.
See pages 5-6 of this document to learn how
to copy this output into Excel

ASIDE: PRACTICE (~2 min)Drag the names of some other categorical variables into the Variable 1 slot - ensure you
can get simple graphs and tables like the above quickly for each variable.
Colouring the bars
•Having ‘Race3’ variable in Variable 1 slot, click on the Add to Plot icon located beneath theplot window. (Add to Plot can also be found in top menu: Plot > Add to plot …)•Customise plot appearance appears
in the first field by default.

•Under Colour by choose Race3.

Try changing the colour Palette torainbow(hcl).

Displaying Categorical Variables in iNZight

Page 2 of 6

Reordering the bars by frequency
iNZight initially displays the bars of a graph in alphanumeric order. From the top menu:•

select Variables > Categorical Variables > Reorder
Levels

•A new window which appears, select Race3 from thedrop down list beside Variable to reorder•

give the variable a new name or accept the nameoffered, Race3.reord•

Select Sort by: Frequency and click REORDER.

This does not change the graph. It just creates a newvariable that has the desired ordering – you can then plot
this new variable.

•Select the Home button (at bottom)
to return to the Home command
panel so that you can plot othervariables.

•Drag Race3.reord (or your new variable name) into the Variable1 slot.

•

Choose colour by Race3.reord.

(Here the so-called Colourblind friendly
palette has been nominated.)
This is an example of a Pareto chart –appropriate for nominal variables.

Displaying Categorical Variables in iNZight

Page 3 of 6Troubleshooting•I resized the window and my plot disappeared.
 Click the Redraw plot icon (you can hover over the icons to see what they do).

•How do I remove the colour segmentation in the bars?
 You have a colour-by setting that is still active. Go to Remove Additions underneaththe plot and then use Remove colour by.

•The plot didn’t change when I used reorder categories and clicked “Reorder”.
 Clicking re-order does not create a new graph, it creates a new variable (e.g.
race3.reord).
To get the new (reordered) graph you have to drag/select the new variable.
The behaviour of iNZight Lite is different ….

•My bar labels are on an angle. How do I make them horizontal?
 Stretch the plot window horizontally until there is room for them to become
horizontal and then click the Redraw plot icon (underneath the plot window) toredraw the plot.
Another option is Add to plot and under Overall Plot Appearance, reduce Overall size
scale (makes every plot element smaller).

•How do I modify headings?
 Use Add to Plot > Axes and labels.

•How do I save my graph from iNZight for use in another document?
 Click on the Save Plot icon at the bottom of your graph, or go Plot > Save Plot. There
several formats available, e.g. pdf, png, …

•How do I copy and paste my graph from iNZight into another document?
 Copy and paste only works in Windows. (Otherwise you have to use screen shots.)
Click on the New graphics window icon at the bottom of your graph (you can hoverover the icons to see what they do), then you will have another copy of your graph in a
separate graphics window.
Right click on this new window, and Copy as metafile or Copy as bitmap.

•How can I save the data file so that it remembers the reordering I have done?
 Selecting File > Save … enables you to save the data in a R native format whichremembers all new variables you have created including features like reorderings andrenamings - R is the free statistical computing software used to enable iNZight.
You may then read it back in a new iNZight session using File > Load … .

Additional:• for how to instructions for iNZight you should consult iNZight’s User Guides.
• for technical issues with running iNZight, you should first consult iNZight’s frequently asked
questions (FAQ) page and if the answer you need is not there ask at iNZight support.

Displaying Categorical Variables in iNZight

Page 4 of 6

How to copy summary information to Excel
Highlight the summary and copy:

In Excel, click on Paste and select Use Text Import Wizard:

Choose “Fixed width” and “My data has headers”

Click ‘Next’ – the following should appear

Displaying Categorical Variables in iNZight

Page 5 of 6

Click ‘Next’ and ‘Finish’ – the following should appear

Displaying Categorical Variables in iNZight

Page 6 of 6