20
The Grammar of Graphics Han-Wei Shen CSE 5544

The Grammar of Graphics - Computer Science and …web.cse.ohio-state.edu/~shen.94/5544/Slides/Grammar-1.pdf · of graphics, not charts ... Refined Data Flow ... (ACLS) Reported in

Embed Size (px)

Citation preview

TheGrammarofGraphics

Han-WeiShenCSE5544

Grammar

•  Grammargiveslanguagerules•  Grammarmakeslanguageexpressive– Alanguagecontainswordsbutnorulesexpressesonlyasmanyideasastherearewords

•  GrammarofGraphics–grammaEcalrulesforcreaEngperceivablegraphs–  Takeusfromchartstostatements–  BothmathemaEcalandaestheEc

•  Elegantdesignrequiresustothinkaboutatheoryofgraphics,notcharts

ObjectOrientedGraphicsSystem

•  ThreestagesofgraphiccreaEon–  SpecificaEon

•  TranslaEonofuseracEonsintoaformallanguage]•  RequiredforanautomaEcsystemtounderstandthegraphicrequest

– Assembly•  AssembleagraphicalscenefromaspecificaEon;coordinateitsgeometry,layout,andaestheEcs

– Display•  AestheEcaPributes•  Dynamicdesigntoenablebrushing,drill-down,zooming,linking,etc.

SpecificaEons

•  StaEsEcalgraphicspecificaEonareexpressedinsixstatements– DATA:createvariablesfromdatasets– TRANS:variabletransformaEon– SCALE:scaletransformaEon(e.g.,log)– COORD:acoordinatesystem(e.g.,polar)– ELEMENT:geometry(e.g.,points)andtheiraestheEcaPributes(e.g.,color)

– GUIDE:oneormoreguides(axes,legends,etc.)

Example

Example

MakeaPie

•  Dataflowofmakingapie

– Whatistheformatofthedata– Howarethepiewedgestobecolored?– Whatvariablesshouldbeusedtolabelthepie?– ….

•  TheabovequesEonsarecommontomanycharts.Thegoalofthegrammarsofgraphicsistocreatenewchartsflexibly

Source MakeaPie Renderer

Data Graphic

RefinedDataFlow

•  Theinternalprocessesofmakingapie,whichconsEtutethesyntaxofthegrammarofgraphics

•  Theorderofthefollowingstagesisimportant

VariablesAlgebraScalesStaEsEcsGeometryCoordinatesAestheEc

Source

Renderer

AMoreDetailedExampleAsurveyofUSScholarsCommissionedbytheAmericanCouncilofLearnedSocieEes.(ACLS)ReportedinMortonandPrice(1989)Surveyedwere5385Respondentsnumbered3835Responseratewas71percentAmongrespondents,74%male,26%femaleRespondentsansweredthequesEon:“Howojen,itatall,doyouthinkthe

peerreviewrefereeingsystemforscholarlyjournalsinyourfieldisbiasedinfavorofthefollowingcategoriesofpeople?“…Maleswereoneofthetargetcategories

Thepercentagesofrespondentschoosingeachoffiveadverbsfornowojenthereviewprocessisbiasedinfavorofmales:Males:Rarely(30),Infrequently(15),Occasionally(10),Frequently(7),NotSure(38)Females:Rarely(8),Infrequently(11),Occasionally(17),Frequently(32),NotSure(32)

CreateVariables

•  LoadfromSQL

–  Response=loadFromSQL(“ACLS”,“bias_...”,case”);

–  Gender=loadFromSQL(“ACLS”,”Gender”,“case”);

•  Return

CaseID Gender BiasinfavorofMale … …

CaseID Response

1 Frequently

2 NotSure

3 Frequently

3834 Rarely

3835 Infrequently

CaseID Gender

1 Male

2 Female

3 Male

3834 Male

3835 Female

ApplyAlgebra

•  Algebra:acollecEonof1)sets2)operators3)rulesforthecombinaEonofoperators

•  Jointhetwotablesusingthecross(innerjoin)funcEon

x a xa y b ybz c zc*=

CaseID Response Gender

1 Frequently Male

2 NotSure Female

3 Frequently Male

… … …

3834 Rarely Male

3835 Infrequently Female

ApplyScales

•  DefineanorderforthecategoricalvariableResponseandGender–  CategoricalscaletransformaEon:associatethevaluesofacategoricalvariablewithasetofintegers

–  CanbedonebyalphabeEcal,relaEvefrequency,oranyuserselectedorder

CaseID Response Gender

1 4 2

2 5 1

3 4 2

3835 2 1

Rarely=1;Infrequently=2;Occasionally=3;Frequently=4;Notsure=5Female=1;Male=2

ComputeStaEsEcs

•  UsesummaryproporEon()staEsEcalmethodCaseID Summary Response Gender

Female,Rarely 0.08 1 1

Female,Infrequently 0.11 2 1

Female,Occasionally 0.17 3 1

Female,Frequently 0.32 4 1

Female,Notsure 0.32 5 1

Male,Rarely 0.30 1 2

Male,Infrequently 0.15 2 2

Male,Occasionally 0.10 3 2

Male,Frequently 0.07 4 2

Male,Notsure 0.38 5 2

ConstructGeometry

•  UseintervalgraphwhichconvertsanintervalintoageometricobjectwithalengthproporEonaltotheintervalandanon-zerowidth

•  Interval()willaddalowerbound0totheoutputofthesummary()staEsEcsfuncEon

•  Interval.stack()willaccumulatetheintervalbyincremenEngthelowerandupperboundoftheintervalbytheupperboundofthepreviousinterval

ConstructGeometry

ApplyCoordinates

•  ApplyapolarpolartransformaEontotheshapesthatwereproducedbythegeometry

•  (x,y)->(r,theta)

ComputeAestheEcs

•  Translateagraphintoagraphic•  PosiEon()

–  Input:aregiondefinedbythepolartransformaEonoftheregioncreatedbytheinterval.stack()geometricelementoperaEngonthesummary.proporEon()operaEngonthevarsetcreatedbycrossingResponseandGender

–  Output:thereferencestoscreencoordinates•  Color():

–  Intput:allpossiblevaluesoftheResponsevariable–  Output:pointertotheentriesofacolortable

•  Label():–  Inupt:sameasthatofcolor()–  Output:pointerstothecharacterstringscontainingthelabel

ComputeAestheEcs

SpecificaEon

•  ThefirstlineorlinescontaintheDATAfuncEonsthatcreatevariablesfromdata

•  ThenextlinesgivetheTRANSspecificaEonthatdefinethetransformaEontobeappliedtothevariables

•  ThenextlinesaretheSCALEspecificaEon•  ThenextlinesaretheCOORDspecificaEonthatdefinesthecoordinatesysteminwhichthegraphsaretobeembedded

•  ThenextlinesaretheGUIDEspecificaEonsforaxesandlegends

•  TheremaininglinescontainthegeometricgraphingfuncEons

Result