Module 4 — Graphs
Question: what does the distribution actually look like? Numbers summarize; pictures reveal shape, outliers and comparisons at a glance.
Open the sample (Ctrl+Shift+O). Charts land as cards in the Output View,
interleaved with tables; right-click a card to copy it as an image straight
into a document, or Export image… to save it — see
Taking a chart out of ChakataStat at the end of this
module.
Histogram — one scale variable's shape
Graphs → Histogram… (Ctrl+Shift+H), variable BMI, Run.
A roughly bell-shaped pile centred in the mid-20s with a right tail — real BMI data look like this too. Re-run with the bins slider at different values: more bins show more detail and more noise. The bins are display only — they change no data. (Turning BMI into actual categories is a transform — module 8.)
Boxplot — a scale variable across groups
Graphs → Boxplot… (Ctrl+Shift+B), variable SystolicBP, category
SmokingStatus, Run.
Each box is a group's median and quartiles, whiskers and outlier points. The Current box should sit visibly higher — the picture version of the test you will run in module 6.
Line Chart — a trend across a scale variable
Graphs → Line Chart… (Ctrl+Shift+L), Y series SystolicBP, X axis
Age, split by SmokingStatus, Run.
health_study is one row per participant, not one row per visit, so this connects each smoking group's points in age order rather than tracing a single patient over time — the mechanics are the same chart you would use for a real time series (repeated visits, a stock price, a sensor log). Turn on point markers to see the individual participants along each line.
The Chart Builder
Graphs → Chart Builder… (Ctrl+Shift+G) is the general dialog: pick the
chart type, assign variables to its roles. Rebuild the boxplot above in it,
then try a Scatterplot of BMI (X) against SystolicBP (Y) — the cloud
should visibly climb, previewing module 7's correlation.
Beyond the four chart types this module builds, the Graphs menu also offers Bar Chart, Error Bar and Q-Q Plot, and analyses draw their own charts as part of their output (a forest plot from a meta-analysis, a survival curve from Kaplan-Meier). The Graphs reference is the full catalogue.
Editing a chart after you have drawn it
Every chart card has an Edit chart… button in its header. Press it on the boxplot and the chart editor opens with a live preview beside the controls that chart actually supports — for a boxplot: the title, the y-axis title and range, the colours, gridlines, reference lines and figure height. A line chart or a bar chart offers more (legend placement, marker shape and size, bar stacking), because those charts have more to set.
The editor changes how a chart looks, never what it measures: no control in it can alter a variable, a filter or a statistic. To change the analysis, re-run the command.
Change the title to something a reader would understand, then press Apply.
Now look at the Syntax tab. Your edit is in the command:
boxplot variable=SystolicBP, category=SmokingStatus, title="Systolic pressure by smoking status"
That is the part worth pausing on. ChakataStat did not save your styling somewhere beside the chart — it rewrote the chart's own line in the journal, so re-running the script tomorrow brings the chart back styled exactly as you left it. Presentation is part of the analysis you recorded, not a layer on top of it. Editing a chart covers the editor in full.
Taking a chart out
Right-click a card and choose Export image…. Three formats:
- PNG — a picture at a resolution you choose. For a slide or an email.
- SVG — vector: every line and label still separate and still editable in a drawing program. The format most journals prefer.
- PDF — vector, as a one-page document that opens the same way everywhere.
The two vector formats have no resolution to set, which is the point of them: they redraw sharp at any size, so the resolution control greys out when you pick one. Exporting one chart has the detail.
Exercise
- Histogram of FastingGlucose_mmolL. There is a small second bump well to
the right of the main pile — what is it? (Codebook: a diabetic-range
cluster.) Note that the declared-missing
99s are not in the plot. - Boxplot of BMI by Sex. Do the medians differ much?
- Scatterplot Age (X) vs HeartRate (Y). Describe what "no relationship" looks like — you will want this picture in mind whenever a correlation comes out near zero.
The syntax trail
histogram variable=BMI
boxplot variable=SystolicBP, category=SmokingStatus, title="Systolic pressure by smoking status"
line_chart y=[SystolicBP], x=Age, split=SmokingStatus
scatter x=BMI, y=SystolicBP
Note the boxplot line: it carries the title you typed in the editor. Every chart edit lands in the trail the same way.