Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Grammar of Graphics Ch5. Algebra

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.
Avatar for nacyot nacyot
August 18, 2015

The Grammar of Graphics Ch5. Algebra

2015. 8. 18. 토즈 강남점 발표
정보시각화 고전 스터디 모임 - The Grammar of Graphics Ch5. Algebra 보충
by nacyot http://blog.nacyot.com

이 발표는 정보시각화 고전 스터디에서 발표된 내용으로 Leland Wilkinson의 The Grammar of Graphics의 제 5장 Agebra 파트를 보충 설명하고 있습니다.

https://medium.com/infovis-kr/%EC%A0%95%EB%B3%B4%EC%8B%9C%EA%B0%81%ED%99%94-%EA%B3%A0%EC%A0%84-%EB%8F%85%EC%84%9C-%EB%AA%A8%EC%9E%84-c9b1ef976405

특히 Variable, Varset, Table 등 데이터의 표현 방법들과 연산이 적용되는 과정을 중점적으로 소개하며, 이러한 연산이 어떻게 Frame을 정의하고 그래프로 그려지는 지 보여준다.

Avatar for nacyot

nacyot

August 18, 2015
Tweet

More Decks by nacyot

Other Decks in Technology

Transcript

  1. The Grammar of Graphics Algebra ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ -

    The Grammar of Ghapcis 5੢ © nacyot 2015 - 1
  2. ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ 5ߣ૩ 2015. 8. 18. ੿ࠁदпച Ҋ੹

    ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 2
  3. 2.1.8 Variable a variable is • the domain is a

    set of objects, • the codomain is a set of values, • the function assigns to each element of an element in ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 4
  4. 2.1.8 ߸ࣻ(Variable) ߸ࣻ ח • ੿੄৉ ਷ ё୓ٜ੄ ૘೤ •

    ҕ৉ ਷ чٜ੄ ૘೤ • ೣࣻ ח ੄ п чٜਸ ੄ ਃࣗী ؀਽दఅ׮. ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 5
  5. a set of objects ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The

    Grammar of Ghapcis 5੢ © nacyot 2015 - 6
  6. a set of values ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The

    Grammar of Ghapcis 5੢ © nacyot 2015 - 7
  7. Variable • ప੉࠶ ಴അҗ ࠺त • 1 -> ant •

    2 -> bee • 3 -> drone • 4 -> moth ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 9
  8. 2.1.9 Varsets a varset is • the domain is a

    set of values, • the codomain is a set of all possible bags of objects, • the function assigns to each element of an element in ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 10
  9. 2.1.9 Varsets varset ח • بݫੋ ח чٜ੄ ૘೤ •

    ҕ৉ ח ݽٚ оמೠ ߔ(bags)ٜ੄ ૘೤ • ೣࣻ ח ੄ п чٜਸ ী ؀਽दఅ׮ ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 11
  10. a set of Values ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The

    Grammar of Ghapcis 5੢ © nacyot 2015 - 12
  11. set of all possible bags of objects, ੿ࠁदпച Ҋ੹ ةࢲ

    ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 13
  12. ׮ܲ Variable Y ৘ઁ • 1 -> red • 2

    -> red • 3 -> blue ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 15
  13. Varset Y • red -> <1,2> • blue -> <3>

    ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 16
  14. 2. How To Make a Pie 2.2 Recipe ੿ࠁदпച Ҋ੹

    ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 21
  15. Data Definition Statements SOURCE: <source name> = <fn>(<args>) DATA: <variable

    name> = <fn>(<args>) TRANS: <variable name> = <fn>(<args>) ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 24
  16. SOURCE SOURCE: acls_data = csvSource(path("C:\\acls.csv")) csv file(੉ ઓ੤ೠ׮Ҋ о੿) CaseID,

    Gender, Response, ... 1, Male, Frequently, ... 2, Female, Not Sure, ... 3, Male, Frequently, ... ... 3834, Male, Rarely, ... 3835, Female, Infrequently, ... ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 25
  17. DATA SOURCE: acls_data = csvSource(path("C:\\acls.csv")) DATA: gender = col(source(acls_data), name("Gender"))

    DATA: response = col(source(acls_data), name("Response")) col ೣࣻܳ ా೧ࢲ gender, responce ߸ࣻ ೡ׼ ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 27
  18. gender (2) select CaseID, Gender from acls_data ੿ࠁदпച Ҋ੹ ةࢲ

    ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 29
  19. response (2) select CaseID, Response from acls_data ੿ࠁदпച Ҋ੹ ةࢲ

    ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 31
  20. Algebra৬ Frames (1) Graphics algebra provides a method for specifying

    F(which we call a frame) when we wish to construct agraphic based on some function of a set of data. — nVIZn 3p ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 34
  21. Algebra৬ Frames (2) This chapter deals with restoring and balancing

    sets of variables in order to create the specification for the frames in which graphs are embedded. — GoG Ch5. Algebra 63p ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 35
  22. Frame੉ۆ? A frame is a set of tuple ranging over

    all possible values in the domain of a p- dimensional varset. — GoG 30p Ӓې೐о Ӓ۰૑ח ҕрਸ ੿੄. (2ѐ varset੉ ੓ਸ ٸח ੌ߈੸ਵ۽ xyಣݶҗ э਷ 2ରਗ ಣݶਸ ੿੄) ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 36
  23. Frame Specification • 1౸ীࢲח frame spcification੉ ੓঻਺(40p) FRAME: x *

    y GRAPH: point() • 2౸੄ ಴അߨ(39p) ELEMENT: point(position(x * y)) ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 37
  24. Symbol A symbol is used to represent an entity operated

    on by an algebra. The symbols in varset algebra are varsets. बࠅ਷ ؀ࣻधীࢲ ҅࢑غয૑ח ೦ݾਸ աఋմ׮. varset ؀ࣻधীࢲ बࠅ਷ varset੉׮. ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 38
  25. Operators An operator is a method for relating symbols in

    an algebra. ো࢑੗ח ؀ࣻधীࢲ बࠅٜਸ ҙ҅૙ח ݫࢲ٘੉׮. • Cross(*), Nest(/), Blend(+) • Varsets( and ) • Value Domain of Varsets( and ) ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 39
  26. Cross( ) ࣻ೟੸ ੿੄ Varset ੿੄ Cross ੿੄ ੿ࠁदпച Ҋ੹

    ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 41
  27. SELECT DISTINCT color.color, car.car FROM color CROSS JOIN car; color

    car ---------- ---------- red supercar red sportcar red minicar blue supercar blue sportcar blue minicar ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 43
  28. (1) sql SELECT ('(' || color.color || ', ' ||

    car.car || ')') AS "Value Domain", GROUP_CONCAT( CASE WHEN color.key = car.key THEN color.key ELSE NULL END ) AS "Set of Cases" FROM color CROSS JOIN car GROUP BY "Value Domain"; ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 45
  29. (2) result Value Domain Set of Cases ---------------- ------------ (blue,

    minicar) 3 (blue, sportcar) 2 (blue, supercar) (red, minicar) (red, sportcar) (red, supercar) 1,4 ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 46
  30. Cross੄ ప੉࠶(Variable) ಴അ SELECT color.key, color.color, car.car FROM color, car

    WHERE color.key = car.key; ױ, ੿੄৉( ) ੹୓о ಴അػ׮ח ࠁ੢਷ হ਺. ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 47
  31. Cross৬ Nest੄ ࣻ೟੸ ੿੄ Cross( ) Nest( ) ੿ࠁदпച Ҋ੹

    ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 50
  32. SELECT DISTINCT color.color, car.car FROM color INNER JOIN car WHERE

    color.key = car.key; color car ---------- ---------- red supercar blue sportcar blue minicar ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 52
  33. # cross # nest color car color car ---------- ----------

    ---------- ---------- red supercar red supercar red sportcar blue sportcar red minicar blue minicar blue supercar blue sportcar blue minicar ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 53
  34. Value Domain Set of Cases ---------------- ------------ (blue, minicar) 3

    (blue, sportcar) 2 (blue, supercar) (red, minicar) (red, sportcar) (red, supercar) 1,4 ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 55
  35. Value Domain Set of Cases ---------------- ------------ (blue, minicar) 3

    (blue, sportcar) 2 (red, supercar) 1,4 SELECT ('('||color.color||','||car.car||')') AS "Value Domain", GROUP_CONCAT(car.key) as "Set of Cases" FROM color INNER JOIN car WHERE color.key = car.key GROUP BY "Value Domain"; ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 56
  36. Nest ো࢑੄ ৉ೡ (1) Wilkinson presents three algebraic operators called

    cross ( ), nest( ), and blend ( ), together with the rules for their use. Theyare derived from the set operators product ( ), discreteunion ( ), and union ( ), respectively. — nVIZn 3p ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 58
  37. Nest ো࢑੄ ৉ೡ (2) The disjoint union of two sets

    A and B, denoted by A B, produces a set whose members are tagged elements. A tagged element is one of the form x:$, where x X is the element and the symbol $ is the tag. A tag is some- times called an identifier or a color; it may be a string, a numerical value, or another piece of information. — GoG 26p ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 59
  38. Nest ো࢑੄ ৉ೡ (3) The nesting variable tags the nested

    variable such that (s, t) implies (s : t). We will not use this notation below, but we will assume an algebra system can identify the nesting elements through a tagging index. — GoG 65p ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 60
  39. Nest ো࢑੄ ਊب • Tagging • Data values • Metadata

    • Data organization ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 61
  40. d3.js੄ nest ೣࣻ۽ ੉೧ೞӝ (1) data = [ {color: 'red',

    car: 'supercar'}, {color: 'blue', car: 'sportcar'}, {color: 'blue', car: 'minicar'}, {color: 'red', car: 'supercar'} ] ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 63
  41. d3.js੄ nest ೣࣻ۽ ੉೧ೞӝ (2) var nestedData = d3.nest() .key(function(d)

    { return d.car; }) .map(dataSet); { 'supercar':[ {color: 'red', car: 'supercar'}, {color: 'red', car: 'supercar'}, ], 'sportcar':[ {color: 'blue', car: 'sportcar'}, ], 'minicar':[ {color: 'blue', car: minicar'}, ] } ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 64
  42. ೦١ਗ(Identity emelemnt) • +੄ ೦١ਗ: ҕ૘೤ • cross৬ nest੄ ೦١ਗ

    varset • ରࣻ(order)ܳ ݏ୶ӝ ਤ೧ࢲب ࢎਊ ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 68
  43. Expression • term(expression with no + operator) • factor(expression with

    no * operator) • monomial(one term) • polynomial(more than one term) • order(number of factors in term) • k(largest order among the monomials) ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 70
  44. Algebraic Form An algebraic form is a monomial or a

    polynomial whose terms all have the same number of factors. • • • • ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 71
  45. ৵ ରࣻܳ ݏ୾ঠೡө? • ରࣻח Ӓې೐о Ӓ۰૑ח ҕр੄ ରਗਸ Ѿ੿

    • ରࣻо эইঠ Blend ো࢑ਸ ೡ ٸ ੄޷ܳ о૗ ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 72
  46. pop1980 * 1 COORD: rect(dim(1, 2)) ELEMENT: point(position(pop1980 * 1))

    # FRAME = [0, 30] x unity ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 78
  47. pop1980 * pop2000 COORD: rect(dim(1,2)) ELEMENT: point(position(pop1980*pop2000)) # FRAME =

    [0, 30] x [0, 30] ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 79
  48. ଼੄ ৘ઁ (1) ELEMENT: point(position(city*pop1980*group)) # FRAME = (Tokyo, ...)

    x [0, 30] x (World, USA) ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 81
  49. ଼੄ ৘ઁ(2) - ખ ؊ ੿ഛೠ ಴അ COORD: rect(dim(3), rect(dim(1,2)))

    ELEMENT: point(position(city*pop1980*group)) ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 82
  50. খ੄ ৘ઁܳ 3ରਗਵ۽ COORD: rect(dim(1,2,3)) ELEMENT: point(position(city*pop1980*group)) # FRAME =

    (Tokyo, ...) x [0, 30] x (World, USA) ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 84
  51. World, USA ಣݶਸ ٮ۽ ಟ୛֬ӝ ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ -

    The Grammar of Ghapcis 5੢ © nacyot 2015 - 90
  52. city * pop1980 * group • э਷ 2ରਗ Frame(city*pop1980)੄ ಣݶٜ

    COORD: rect(dim(3), rect(dim(1,2))) ELEMENT: point(position(city*pop1980*group)) ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 91
  53. ࢲ۽ ׮ܲ 2ѐ੄ ಣݶ! ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The

    Grammar of Ghapcis 5੢ © nacyot 2015 - 95
  54. Figure 5.6 DATA: p1980 = "1980" DATA: p2000 = "2000"

    ELEMENT: point(position(city*(pop1980+pop2000)), color(p1980 + p2000)) ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 98
  55. Frame of Figure 5.6 • city*(pop1980+pop2000) element: point(position(city*(pop1980+pop2000))) # FRAME

    = {Tokyo, ...} x [0, 30] • city*pop2000 element: point(position(city*pop2000)) # FRAME = {Tokyo, ...} x [0, 30] ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 99
  56. Color Blend Operator GoG 310p ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ -

    The Grammar of Ghapcis 5੢ © nacyot 2015 - 100
  57. Figure 5.6, again DATA: p1980 = "1980" DATA: p2000 =

    "2000" ELEMENT: point(position(city*(pop1980+pop2000)), color(p1980 + p2000)) ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 101
  58. Figure 5.8 DATA: p1980 = "1980" DATA: p2000 = "2000"

    ELEMENT: point(position((city/group)*(pop1980+pop2000), color(p1980 + p2000)) ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 102
  59. Figure 5.9 DATA: p1980 = "Pop 1980 (millions)" DATA: p2000

    = "Pop 2000 (millions)" ELEMENT: point(position(city*(pop1980/p1980+pop2000/p2000))) ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 103
  60. ggplot2۽ ch5 ৘ઁ ੤ҳഅ GOG ch5 Varget Algebra Example -

    Gist ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 104
  61. ggplot2৬ GoG • ggplot2 • Varset Algebra ѐ֛ਸ ૑ਗೞ૑ ঋ਺

    • दпചೞח data.frameਸ ޷ܻ ઑ੘೧ঠೣ scales = 'free' ২࣌ਵ۽ nest৬ ࠺तೞѱ ҳഅ ggplot(pop, aes(x = city2, y = pop2000_d)) + geom_point(colour = I('darkblue')) + # scales = 'free'ܳ ా೧ࢲ ಣݶীࢲ ҕ૘೤੉ غח (a, b) ஠పҊܻܳ ઁѢ facet_grid(. ~ group, scales = 'free') + scale_y_continuous(limits=c(0, 30)) ੿ࠁदпച Ҋ੹ ةࢲ ݽ੐ - The Grammar of Ghapcis 5੢ © nacyot 2015 - 105