- Variable types
- Mapping variable to plot elements
- Bar plots with Vega
September 22 2022
Numeric variables are also known as quantitative variables.
Illustration by Alisson Horst (https://github.com/allisonhorst/stats-illustrations)
Can you think of examples of these two types of numeric variables?
What are good visualization mappings (or encodings) for continuous and discrete numeric variables?
Categorical variables are also known as qualitative or nominal variables.
Illustration by Alisson Horst (https://github.com/allisonhorst/stats-illustrations)
Can you think of examples of these two types of categorical variables?
What are good encodings for ordered and unordered categorical variables?
We will be using the aggregated data for our first bar plot with Vega.
Download the starter code for the project.
Make changes to the bigfoot.js
file.
Create two scales in your spec, one for the y axis and another for the y axis. If you are mapping continuous numeric variables, use a linear
scale. For categorical variables, use a band
scale.
Include a name
, type
, domain
and range
properties for each scale
For range
you can use the values height
and width
For the domain
use the following syntax:
{ data: "dataName", field: "variableName" }
scale
– use the ones you createdorient
, which can be "bottom"
,"left"
, "right"
and "top"
What do the following properties do?
offset
tickCount
grid
Any other interesting property?
marks
if type
"rect"
from
property with the data
property mapped to the name you gave your dataencode
define an enter
property with your y
and x
axes, a fixed height (of 20 for example) and either a y2
or x2
with value 0 (depending on where you are mapping your categorical variable to)What type of variable is state
in our bigfoot data?
transform
property in your data object with:
type: "collect"
sort
by the n
field with descending
order
type
“text”Add another object to the data array
Give it a name
, and the source
is the name you gave to the json being imported
Add a transform
property, which takes as value an array – add an object to this array, with type: "window"
and ops: ["row_number"], as: ["rank"]
Add another transform
property with type: "filter"
and the following expression:
expr: "datum.rank <= 5"
Add any titles and labels you think are needed