graph
Draws a chart and saves it as a web page you can open, email or embed.
What we have
- 22 chart types, listed in the gallery
- statistics:
count,max,mean,median,min,sum over(),by(),title(),ytitle()andsaving()- each chart is one self-contained
.htmlfile with no internet needed
Coming later
graph twowayandgraph matrix, which are refused- saving as PNG or SVG;
graph exportdoes not exist yet - 84 more of the 105 catalogue chart types
How you write it
graph <kind> [(stat)] varname [if] [weight] [, over() by() ...]
Square brackets mean optional. A vertical bar means choose one.
What it does
graph bar mpce, over(state) writes a self-contained .html file: one file, no internet connection needed, opens in any browser. Every number in it was worked out in Python before the page was written — the page only draws.
Twenty-one chart types are built. The shape of the command is the same for all of them:
- the kind —
bar,line,scatter,histogramand the rest - an optional statistic in brackets —
(mean)by default, or(sum),(median),(count) - the variable being measured
over()— the categories along the axisby()— a second split, drawn as colours, panels or sides
See the chart gallery for all of them, each with its own page, a live example and the shape your data needs to be in.
Watch out. Every chart wants long data: one row per person or record. If your years sit in separate columns (
income2004, income2006), run reshape long first.Try it
Every example below was run after sysuse vira.sample01, clear.
. graph bar mpce, over(state)
(graph saved to graph_mpce.html)
The same thing in pandas and in R
pandas
# rendered with D3; see graph_mpce.html
R
# no R form for `graph` yet -- see docs/r-equivalents.md