Force-directed diagrams Philippe Van Kerm University of Luxembourg - - PowerPoint PPT Presentation

force directed diagrams
SMART_READER_LITE
LIVE PREVIEW

Force-directed diagrams Philippe Van Kerm University of Luxembourg - - PowerPoint PPT Presentation

Fancy graphics #1 Force-directed diagrams Philippe Van Kerm University of Luxembourg and LISER 2020 e-London Stata user group meeting September 11, 2020 [ Outline ] Examples Principles and mechanics Implementation Examples Principles and


slide-1
SLIDE 1

Fancy graphics #1

Force-directed diagrams

Philippe Van Kerm

University of Luxembourg and LISER

2020 e-London Stata user group meeting September 11, 2020

slide-2
SLIDE 2

[ Outline ]

Examples Principles and mechanics Implementation

slide-3
SLIDE 3

Examples Principles and mechanics Implementation

slide-4
SLIDE 4

My starting point...

a: AGRCULTURE, FORESTRY, FISHERY b-e: MINING AND QUARRYING/MANUFACTURING/ELECTRICITY GAS STEAM AIR CONDITIONING SUPPLY/WATER SUPPLY; (+ OTHER INDUSTRIES) f: CONSTRUCTION g: WHOLESALE AND RETAIL TRADE; REPAIR OF MOTOR VEHICLES AND MOTORCYCLES h: TRANSPOT AND STORAGE i: ACCOMMODATION AND FOOD SERVICE ACTIVITIES j: INFROMATION AND COMMUNICATION k: FINANCIAL AND INSURANCE ACTIVITIES l-n: REAL ESTATE ACTIVITIES, PROFESSIONAL SCIENTIFIC AND TECHNICAL ACTIVITIES/ADMINISTRATIVE AND SUPPORT SERVICE ACTIVITIES

  • : PUBLIC ADMINISTRATION AND DEFENCE; COMPULSORY SOCIAL SECURITY

p: EDUCATION q: HUMAN HEALTH AND SOCIAL WORK ACTIVITIES r - u: R-U:ARTS ENTERTAINMENT AND RECREATION/OTHER SERVICE ACTIVITIES/ACTIVITIES OF HOUSEHOLDS AS EMPLOYERS; (+ FEW OTHERS) a b - e f g h i j k l - n

  • p

q r - u

slide-5
SLIDE 5

Network visualisation (as a force-directed diagram)

– The matrix is a network – Each sector is a node – Sectors with strong ‘bedroom association’ located near each other – (See Thomas Grund’s ♥✇❝♦♠♠❛♥❞s for serious network analysis with Stata; Corten (SJ, 2011), Miura (SJ, 2012).)

2 4 5 6 7 8 9 10 12 13 1 3 11

Economic sectors in the bedroom

slide-6
SLIDE 6

Network visualisation (as a force-directed diagram)

– The matrix is a network – Each sector is a node – Sectors with strong ‘bedroom association’ located near each other – (See Thomas Grund’s ♥✇❝♦♠♠❛♥❞s for serious network analysis with Stata; Corten (SJ, 2011), Miura (SJ, 2012).)

2 4 5 7 8 9 10 1 6 12 13 11 3

Economic sectors in the bedroom

slide-7
SLIDE 7

Another network visualisation (as a force-directed diagram)

Clervaux Vianden Wiltz Diekirch Echternach Grevenmacher Remich Luxembourg Esch Capellen Redange Mersch

slide-8
SLIDE 8

Another network visualisation (as a force-directed diagram)

Clervaux Vianden Wiltz Diekirch Echternach Grevenmacher Remich Luxembourg Esch Capellen Redange Mersch

slide-9
SLIDE 9

Another network visualisation package in the making

❢❞♥❡t❣r❛♣❤ varname

  • if

in

  • ✱ ❧✐♥❦s✭fromvar tovar

[strengthvar]✮

  • s❤♦✇❧✐♥❦s✭✳✳✳✮

✈❛r❝♦❧♦r✭✈❛r♥❛♠❡✮ ✳✳✳

  • (too many options to discuss here (fiddling with the

construction and display options; see below))

Clervaux Vianden Wiltz Diekirch Echternach Grevenmacher Remich Luxembourg Esch Capellen Redange Mersch

slide-10
SLIDE 10

Other force-directed diagrams: ‘beeswarm’ plots

Worried about the economy?

slide-11
SLIDE 11

Other force-directed diagrams: ‘beeswarm’ plots

Worried about the economy?

Not at all (left) A lot (right)

Worried about the economy in general?

slide-12
SLIDE 12

Other force-directed diagrams: ‘beeswarm’ plots

Worried your own finances?

Not at all (left) A lot (right)

Worried about Your own financial situation?

slide-13
SLIDE 13

Other force-directed diagrams: ‘beeswarm’ plots

Worried your health?

Not at all (left) A lot (right)

Worried about your own health?

slide-14
SLIDE 14

Other force-directed diagrams: ‘beeswarm’ plots

Worried about your friend and family’s health?

Not at all (left) A lot (right)

Worried about health of friends and family?

slide-15
SLIDE 15

Variations on the same theme: other ‘beeswarm’ plots

The evolution of employment: telework, short-time employment, ‘parental’ leave, sick leave, job loss February early April June

February ...

slide-16
SLIDE 16

Variations on the same theme: other ‘beeswarm’ plots

The evolution of employment: telework, short-time employment, ‘parental’ leave, sick leave, job loss February early April June

April ...

slide-17
SLIDE 17

Variations on the same theme: other ‘beeswarm’ plots

The evolution of employment: telework, short-time employment, ‘parental’ leave, sick leave, job loss February early April June

end May / early June ...

slide-18
SLIDE 18

A beeswarm plot package in the making

❜❡❡s✇❛r♠ ❬varname❪

  • if

in

  • ✳✳✳✈❛r❝♦❧♦r✭✈❛r♥❛♠❡✮ ✈❛rs②♠❜♦❧✭✈❛r♥❛♠❡✮✳✳✳
  • (too many options to discuss here (fiddling with the

construction, the display, the choice of locations etc.; see below))

April ...

slide-19
SLIDE 19

What is the commonality?

April ...

Clervaux Vianden Wiltz Diekirch Echternach Grevenmacher Remich Luxembourg Esch Capellen Redange Mersch

slide-20
SLIDE 20

What is the commonality?

– Simple scatterplots... – ... but elements have no pre-defined location on the canvas – Key to the drawing is calculating the plotting positions!

April ...

slide-21
SLIDE 21

Examples Principles and mechanics Implementation

slide-22
SLIDE 22

Force-directed layouts

– Element positions determined by a stochastic simulation algorithm – Elements “interact” with each other in order to find their position on the canvas – Interactions through combinations of few simple forces:

» Gravitational forces (positive or negative; attractions or repulsion) » Spring forces (towards target distances) » Collisions

– Start from random positions and iterate until convergence to a stable plot – Stochastic: randomness in the resulting plot (set your s❡❡❞)!

slide-23
SLIDE 23

Force-directed layouts

– Element positions determined by a stochastic simulation algorithm – Elements “interact” with each other in order to find their position on the canvas – Interactions through combinations of few simple forces:

» Gravitational forces (positive or negative; attractions or repulsion) » Spring forces (towards target distances) » Collisions

– Start from random positions and iterate until convergence to a stable plot – Stochastic: randomness in the resulting plot (set your s❡❡❞)!

slide-24
SLIDE 24

Force-directed layouts

– Element positions determined by a stochastic simulation algorithm – Elements “interact” with each other in order to find their position on the canvas – Interactions through combinations of few simple forces:

» Gravitational forces (positive or negative; attractions or repulsion) » Spring forces (towards target distances) » Collisions

– Start from random positions and iterate until convergence to a stable plot – Stochastic: randomness in the resulting plot (set your s❡❡❞)!

slide-25
SLIDE 25

Different combination of forces lead to different types of plots

Attraction forces between points and towards ‘anchors’ (hives) + collisions

April ...

Spring forces to target connected node distances and repulsion

Clervaux Vianden Wiltz Diekirch Echternach Grevenmacher Remich Luxembourg Esch Capellen Redange Mersch

slide-26
SLIDE 26

Example for a beeswarm plot

Positioning trail

slide-27
SLIDE 27

Example for a beeswarm plot

Positioning trail

slide-28
SLIDE 28

Example for a beeswarm plot

Positioning trail

slide-29
SLIDE 29

Example for a beeswarm plot

Positioning trail

slide-30
SLIDE 30

Example for a beeswarm plot

Positioning trail

slide-31
SLIDE 31

Example for a beeswarm plot

Positioning trail

slide-32
SLIDE 32

Example for a beeswarm plot

Positioning trail

slide-33
SLIDE 33

Example for a beeswarm plot

Positioning trail

slide-34
SLIDE 34

Example for a beeswarm plot

Positioning trail

slide-35
SLIDE 35

Example for a beeswarm plot

Positioning trail

slide-36
SLIDE 36

Example for a beeswarm plot

Positioning trail

slide-37
SLIDE 37

Example for a beeswarm plot

Positioning trail

slide-38
SLIDE 38

Example for a beeswarm plot

Positioning trail

slide-39
SLIDE 39

Example for a beeswarm plot

Positioning trail

slide-40
SLIDE 40

Example for a beeswarm plot

Positioning trail

slide-41
SLIDE 41

Example for a beeswarm plot

Positioning trail

slide-42
SLIDE 42

Example for a beeswarm plot

Positioning trail

slide-43
SLIDE 43

Example for a beeswarm plot

Positioning trail

slide-44
SLIDE 44

Example for a beeswarm plot

Positioning trail

slide-45
SLIDE 45

Example for a beeswarm plot

Positioning trail

slide-46
SLIDE 46

Example for a beeswarm plot

Positioning trail

slide-47
SLIDE 47

Example for a beeswarm plot

Positioning trail

slide-48
SLIDE 48

Example for a beeswarm plot

Positioning trail

slide-49
SLIDE 49

Example for a beeswarm plot

Positioning trail

slide-50
SLIDE 50

Example for a beeswarm plot

Positioning trail

slide-51
SLIDE 51

Examples Principles and mechanics Implementation

slide-52
SLIDE 52

Implementation

❜❡❡s✇❛r♠

✳✳✳ ❙t❛t❛ ❝♦❞❡ ✳✳✳ ♣❛rs✐♥❣ ❞❛t❛ ✳✳✳ ✳✳✳ ▼❛t❛ ❝❛❧❧ ✳✳✳ ✳✳✳ ♣❛ss ✈✐❡✇s ✳✳✳ ✳✳✳ ❝r❡❛t❡ ❛♥ ✐♥st❛♥❝❡ ♦❢ ❛ ❙✇❛r♠ ❝❧❛ss ✳✳✳ ✳✳✳ r✉♥ s✐♠✉❧❛t✐♦♥ ✭❙✇❛r♠✳❢❧② ✭✮✮ ✳✳✳ ✳✳✳ ❙t❛t❛ ❣r❛♣❤✐❝s ❝♦❞❡ ✳✳✳ ✳✳✳ ❝❧❡❛r ❝❛♥✈❛s ✳✳✳ ✳✳✳ s❝❛tt❡r ❛♥❞ ♣❝s♣✐❦❡ ✳✳✳

❢❞♥❡t❣r❛♣❤

✳✳✳ ❙t❛t❛ ❝♦❞❡ ✳✳✳ ♣❛rs✐♥❣ ❞❛t❛ ✳✳✳ ✳✳✳ ▼❛t❛ ❝❛❧❧ ✳✳✳ ✳✳✳ ♣❛ss ✈✐❡✇s ✳✳✳ ✳✳✳ ❝r❡❛t❡ ❛♥ ✐♥st❛♥❝❡ ♦❢ ❛ ❙✇❛r♠ ❝❧❛ss ✳✳✳ ✳✳✳ r✉♥ s✐♠✉❧❛t✐♦♥ ✭❙✇❛r♠✳❢❧② ✭✮✮ ✳✳✳ ✳✳✳ ❙t❛t❛ ❣r❛♣❤✐❝s ❝♦❞❡ ✳✳✳ ✳✳✳ ❝❧❡❛r ❝❛♥✈❛s ✳✳✳ ✳✳✳ s❝❛tt❡r ❛♥❞ ♣❝s♣✐❦❡ ✳✳✳

Generic component ▼❛t❛ ❧✐❜r❛r② ❞❡❢✐♥✐♥❣ ❛ ❙✇❛r♠ ❝❧❛ss

slide-53
SLIDE 53

Main variables and functions of the Swarm class

The Swarm class is the engine which calculates the element positions and pass it back to calling ado file.

❝❧❛ss s✇❛r♠ ④ ✴✴ ❱❛r✐❛❜❧❡s✿ r❡❛❧ ♠❛tr✐① ❇❡❡P♦s ✴✴ ♣♦s✐t✐♦♥s r❡❛❧ ♠❛tr✐① ❇❡❡❱❡❧ ✴✴ ✈❡❧♦❝✐t✐❡s ✭♠♦✈❡♠❡♥t✮ r❡❛❧ ♠❛tr✐① ❇❡❡❆❝❝ ✴✴ ❛❝❝❡❧❡r❛t✐♦♥s r❡❛❧ ♠❛tr✐① ❇❡❡▲✐♥❦s ✴✴ ❝♦♥♥❡❝t✐♦♥s ❝❧❛ss ♣❛r❛♠s s❝❛❧❛r P❛r❛♠s ✴✴ ❧♦♥❣ ❧✐st ♦❢ ❢♦r❝❡ ♣❛r❛♠❡t❡rs ✳✳✳ ✴✴ ❋✉♥❝t✐♦♥s✿ ✳✳✳ ⑥ ❝❧❛ss s✇❛r♠ ④ ✴✴ ❱❛r✐❛❜❧❡s✿ ✳✳✳ ✴✴ ❋✉♥❝t✐♦♥s✿ ✈♦✐❞ ✐♥✐t✐❛❧✐③❡ ✭✮ ✈♦✐❞ ❢❧②✭✮ r❡❛❧ ♠❛tr✐① ❝❡♥t❡r✐♥❣❋♦r❝❡ ✭✮ r❡❛❧ ♠❛tr✐① ❢❧②✐♥❣❤♦♠❡❋♦r❝❡ ✭✮ r❡❛❧ ♠❛tr✐① ♣❡❡r❜❡❡t❡r❛❝t✐♦♥❋♦r❝❡ ✭✮ ✳✳✳ ⑥

slide-54
SLIDE 54

Pros and cons of Stata here

  • – Great combo:

» Stata for handling and parsing source data » Mata for handling calculations/simulations

– Mata (class) programming is neat – t✇♦✇❛② ❣r❛♣❤ commands flexible (more than they may seem)

  • – t✇♦✇❛② ❣r❛♣❤ can be impractical ...

» Controlling graph element dimensions (Aaargh!) » Plotregion dimension as residual (Ouch!) » Marker dimensions with weights?? » (NB: no graph class digging—higher-level t✇♦✇❛② ❣r❛♣❤ commands only)

– Animation (and interaction) gives force-directed graphs another dimension —❤tt♣s✿✴✴❢❧♦✇✐♥❣❞❛t❛✳❝♦♠✴✷✵✶✾✴✵✸✴

✵✻✴✇♦♠❡♥✲♠❡♥✲t✐♠❡✉s❡✴ (see p5 or d3)

slide-55
SLIDE 55

Thanks!

Comments and suggestions welcome.

❜❡❡s✇❛r♠ and ❢❞♥❡t❣r❛♣❤ will be ‘released’ in the coming weeks/months (it needs

a bit of fine-tuning and documentation!)