Variables & Visualization

What Is The Story You Are Trying To Tell?

Andy Grogan-Kaylor

2026-11-25

Possibilities

possible visualizations

possible visualizations

Background

  • Deciding upon the right data visualization to represent your data can be a daunting process.
  • I believe that a starting point for this thinking is some basic statistical thinking about the type of variables that you have.
  • At the broadest level, variables may be conceptualized as categorical variables, or continuous variables.

Data Often Come From A Survey Questionnaire.

hypothetical questionnaire

hypothetical questionnaire

What is Data?

A data set is nothing more than a series of rows and columns that contain answers to responses to a survey.

  • Rows are usually used for individuals, while columns indicate the questionnaire answers, or measures, from those people.
  • Answers to questions are often given numerical responses (e.g. “no” is frequently coded as “0” and “yes” is frequently coded as “1”)
Table 1: hypothetical data
person Q1 Q2 Q3
1 1 0 100
2 2 0 200
3 1 1 -9

Some Notes on Data

  • In working through our research questions, we’ll constantly be going back and forth between the actual data (to see the pattern of responses) and the documentation, to figure out the actual question asked as well as how the different responses are coded.
  • Often in a spreadsheet, you’ll see the full text of a question written out (e.g. “What is your gender identity”?)
  • Most programs that work with data are going to want abbreviations (e.g. “Q1” or “gender”“) for the questions. These abbreviations should usually have no spaces and be 8 characters or less.

Missing Data

  • One cell of Table 1 has a negative number.
  • Frequently negative numbers are used to indicate what are called “missing values”. A missing value is a response like “don’t know”” or “refused to answer” or “did not answer”.
  • Before we start doing calculations with our data, we’ll want to change negative numbers to true missing values (usually symbolized by a “.” or “NA”, so that they don’t goof up our calculations.)

What are Variables?

  • By variables, I simply mean the columns of data that you have.
  • For our purposes, you may think of variables as synonymous with questionnaire items, or columns of data.

Variable Types

  • categorical variables represent unordered categories like neighborhood, or religious affiliation, or place of residence.
  • continuous variables represent a continuous scale like a mental health scale, or a measure of life expectancy.

A Data Visualization Strategy

Once we have discerned the type of variable that we have, there are some follow-up questions that we should ask before deciding upon a chart strategy. These questions have to do with the number of dimensions of our data that we are trying to visualize. Usually, we are trying to visualize only 1 or 2 dimensions of the data:

  • Is our graph about one thing at a time?
    • How much of x is there?
    • What is the distribution of x?
  • Is our graph about two things at a time?
    • What is the relationship of x and y?
    • How are x and y associated?

More On Strategy

a data visualization strategy

a data visualization strategy

Simulated Data

This example uses simulated data on social work clients, of the kind that a social service agency might collect.

Table 2: first few lines of data
Simulated Data
age mental_health group neighborhood
38.3 88.97 Group A Neighborhood B
40.98 125.2 Group A Neighborhood B
23.79 105.1 Group A Neighborhood A

Show One Thing At A Time

We start by visualizing one indicator at a time.

Continuous Variable

Sometimes the most interesting visualizations, are visualizations that give us a sense of the maximum, minimum, and average values. For example, the histogram and dotplot display information on age.

histogram and dotplot

histogram and dotplot

Categorical Variable

We would use a slightly different visualization, for example, a barchart, when our data are grouped into categories.

barchart with counts by neighborhood

barchart with counts by neighborhood

Show The Relationship Of Two Things

Our task becomes somewhat more complicated when we want to understand the relationship of one thing to another thing.

Categorical by Categorical

Here, for example, we visualize two categorical variables, neighborhood, by group. In this graph, the height of the bars represents the count of observations.

barchart with counts by neighborhood and by group

barchart with counts by neighborhood and by group

Continuous by Continuous

Here, we visualize two continuous variables, mental health, by age.

scatterplot of mental health by age

scatterplot of mental health by age

Continuous by Categorical

Last, we visualize a continuous variable by a categorical variable, mental health, by group. In this graph, the height of the bars represents the mean score.

barchart with means of mental health by group

barchart with means of mental health by group

Show Where Something Is

Sometimes our task is different. We want to visualize information, but add information on spatial location, using a map.

Map

map of client locations

map of client locations

Conclusion

  • Data visualization can become complicated.
  • However, good basic data visualization begins with:
    • Understanding the nature of our variables.
    • Understanding how many dimensions of the data we are trying include in a single visualization.

References

Note

Visualizations were made with the ggplot2 (Wickham, 2016) graphing library created by Hadley Wickham.

Wickham, H. (2016). ggplot2: Elegant graphics for data analysis. Springer-Verlag New York. https://ggplot2.tidyverse.org