The Grammar of Graphics - Computer Science and...
Transcript of The Grammar of Graphics - Computer Science and...
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.)
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
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
SpecificaEon
• ThefirstlineorlinescontaintheDATAfuncEonsthatcreatevariablesfromdata
• ThenextlinesgivetheTRANSspecificaEonthatdefinethetransformaEontobeappliedtothevariables
• ThenextlinesaretheSCALEspecificaEon• ThenextlinesaretheCOORDspecificaEonthatdefinesthecoordinatesysteminwhichthegraphsaretobeembedded
• ThenextlinesaretheGUIDEspecificaEonsforaxesandlegends
• TheremaininglinescontainthegeometricgraphingfuncEons