Star Trek in stardate order

By popular demand: Star Trek in stardate order. Discovery is not in the list. I think we still have to figure out if it is a heretical series, or if it fits into the correct, and only true timeline.

Series Season Title Episode (Star)date(s) Stardate used for sorting
ENT 1 Broken Bow 1×01/02 4/16/2151
ENT 1 Fight or Flight 1×03 05-06-2151
ENT 1 Strange New World 1×04 Unknown
ENT 1 Unexpected 1×05 Unknown
ENT 1 Terra Nova 1×06 Unknown
ENT 1 The Andorian Incident 1×07 Unknown
ENT 1 Breaking the Ice 1×08 Unknown
ENT 1 Civilization 1×09 7/31/2151
ENT 1 Fortunate Son 1×10 Unknown
ENT 1 Silent Enemy 1×12 09-01-2151
ENT 1 Cold Front 1×11 09-09-2151
ENT 1 Dear Doctor 1×13 Unknown
ENT 1 Shadows of P’Jem 1×15 Unknown
ENT 1 Sleeping Dogs 1×14 Unknown
ENT 1 Shuttlepod One 1×16 11-09-2151
ENT 1 Fusion 1×17 Unknown
ENT 1 Rogue Planet 1×18 Unknown
ENT 1 Acquisition 1×19 Unknown
ENT 1 Oasis 1×20 Unknown
ENT 1 Detained 1×21 Unknown
ENT 1 Vox Sola 1×22 Unknown
ENT 1 Fallen Hero 1×23 02-09-2152
ENT 1 Desert Crossing 1×24 02-12-2152
ENT 1 Two Days and Two Nights 1×25 2/18/2152
ENT 1 Shockwave 1×26 Unknown
ENT 2 Shockwave, Part II 2×01 Unknown
ENT 2 Carbon Creek 2×02 04-12-2152
ENT 2 Minefield 2×03 Unknown
ENT 2 Dead Stop 2×04 Unknown
ENT 2 A Night in Sickbay 2×05 Unknown
ENT 2 Marauders 2×06 Unknown
ENT 2 The Seventh 2×07 Unknown
ENT 2 The Communicator 2×08 Unknown
ENT 2 Singularity 2×09 8/14/2152
ENT 2 Vanishing Point 2×10 Unknown
ENT 2 Precious Cargo 2×11 09-12-2152
ENT 2 The Catwalk 2×12 9/18/2152
ENT 2 Dawn 2×13 Unknown
ENT 2 Stigma 2×14 Unknown
ENT 2 Cease Fire 2×15 Unknown
ENT 2 Future Tense 2×16 Unknown
ENT 2 Canamar 2×17 Unknown
ENT 2 The Crossing 2×18 Unknown
ENT 2 Judgment 2×19 Unknown
ENT 2 Horizon 2×20 01-10-2153
ENT 2 The Breach 2×21 Unknown
ENT 2 Cogenitor 2×22 Unknown
ENT 2 Regeneration 2×23 03-01-2153
ENT 2 First Flight 2×24 Unknown
ENT 2 Bounty 2×25 3/21/2153
ENT 2 The Expanse 2×26 4/24/2153
ENT 3 The Xindi 3×01 Unknown
ENT 3 Anomaly 3×02 Unknown
ENT 3 Extinction 3×03 Unknown
ENT 3 Rajiin 3×04 Unknown
ENT 3 Impulse 3×05 Unknown
ENT 3 Exile 3×06 Unknown
ENT 3 The Shipment 3×07 Unknown
ENT 3 Twilight 3×08 Unknown
ENT 3 North Star 3×09 Unknown
ENT 3 Similitude 3×10 Unknown
ENT 3 Carpenter Street 3×11 Unknown
ENT 3 Chosen Realm 3×12 Unknown
ENT 3 Proving Ground 3×13 12-06-2153
ENT 3 Stratagem 3×14 12-12-2153
ENT 3 Harbinger 3×15 12/27/2153
ENT 3 Doctor’s Orders 3×16 Unknown
ENT 3 Azati Prime 3×18 2154-01
ENT 3 Hatchery 3×17 01-08-2154
ENT 3 Damage 3×19 Unknown
ENT 3 The Forgotten 3×20 Unknown
ENT 3 3×21 Unknown
ENT 3 The Council 3×22 02-12-2154
ENT 3 Countdown 3×23 2/13/2154
ENT 3 Zero Hour 3×24 2/14/2154
ENT 4 Storm Front 4×01 Unknown
ENT 4 Storm Front, Part II 4×02 Unknown
ENT 4 Home 4×03 Unknown
ENT 4 Borderland 4×04 5/17/2154
ENT 4 Cold Station 12 4×05 Unknown
ENT 4 The Augments 4×06 5/27/2154
ENT 4 The Forge 4×07 Unknown
ENT 4 Awakening 4×08 Unknown
ENT 4 Kir’Shara 4×09 Unknown
ENT 4 Daedalus 4×10 Unknown
ENT 4 Observer Effect 4×11 Unknown
ENT 4 Babel One 4×12 11-12-2154
ENT 4 United 4×13 11/15/2154
ENT 4 The Aenar 4×14 Unknown
ENT 4 Affliction 4×15 11/27/2154
ENT 4 Divergence 4×16 2154-12
ENT 4 Bound 4×17 12/27/2154
ENT 4 In a Mirror, Darkly 4×18 1/13/2155
ENT 4 In a Mirror, Darkly, Part II 4×19 1/18/2155
ENT 4 Demons 4×20 1/19/2155
ENT 4 Terra Prime 4×21 Unknown
TOS 0 The Cage 0x01
TAS 1 The Magicks of Megas-Tu 1×08 1254.4 1254.4
TOS 1 Where No Man Has Gone Before 1×01 1312.4 – 1313.8 1312.4
TOS 1 Mudd’s Women 1×03 1329.8 – 1330.1 1329.8
TOS 1 The Corbomite Maneuver 1×02 1512.2 – 1514.1 1512.2
TOS 1 The Man Trap 1×05 1513.1 – 1513.8 1513.1
TOS 1 Charlie X 1×07 1533.6 – 1535.8 1533.6
TOS 1 The Enemy Within 1×04 1672.1 – 1673.1 1672.1
TOS 1 The Naked Time 1×06 1704.2 – 1704.4 1704.2
TOS 1 Balance of Terror 1×08 1709.2 – 1709.6 1709.2
TOS 1 The Squire of Gothos 1×18 2124.5 – 2126.3 2124.5
TOS 1 What Are Little Girls Made Of? 1×09 2712.4 2712.4
TOS 1 Miri 1×11 2713.5 – 2713.3 2713.5
TOS 1 Dagger of the Mind 1×10 2715.1 – 2715.2 2715.1
TOS 1 The Conscience of the King 1×12 2817.6 – 2819.8 2817.6
TOS 1 The Galileo Seven 1×13 2821.5 – 2823.8 2821.5
TOS 1 Court Martial 1×14 2947.3 – 2950.1 2947.3
TOS 1 The Menagerie, Part I 1×15 3012.4 – 3012.6 3012.4
TOS 1 The Menagerie, Part II 1×16 3013.1 – 3013.2 3013.1
TOS 2 Catspaw 2×01 3018.2 3018.2
TOS 1 Shore Leave 1×17 3025.3 – 3025.8 3025.3
TOS 1 Arena 1×19 3045.6 – 3046.2 3045.6
TOS 1 The Alternative Factor 1×20 3087.6 – 3088.7 3087.6
TOS 1 Tomorrow is Yesterday 1×21 3113.2 – 3114.1 3113.2
TOS 1 Space Seed 1×24 3141.9 – 3143.3 3141.9
TOS 1 The Return of the Archons 1×22 3156.2 – 3158.7 3156.2
TAS 2 The Practical Joker 2×03 3183.3 3183.3
TOS 1 A Taste of Armageddon 1×23 3192.1 – 3193.0 3192.1
TOS 1 The Devil in the Dark 1×26 3196.1 3196.1
TOS 1 Errand of Mercy 1×27 3198.4 – 3201.7 3198.4
TOS 2 The Gamesters of Triskelion 2×17 3211.7 – 3259.2 3211.7
TOS 2 Metamorphosis 2×02 3219.8 – 3220.3 3219.8
TOS 1 Operation — Annihilate! 1×29 3287.2 – 3289.8 3287.2
TOS 2 Amok Time 2×05 3372.7 3372.7
TOS 1 This Side of Paradise 1×25 3417.3 – 3417.7 3417.3
TOS 2 Who Mourns for Adonais? 2×04 3468.1 3468.1
TOS 2 The Deadly Years 2×11 3478.2 – 3479.4 3478.2
TOS 2 Friday’s Child 2×03 3497.2 – 3499.1 3497.2
TOS 2 The Changeling 2×08 3541.9 3541.9
TOS 2 Wolf in the Fold 2×07 3614.9 – 3615.4 3614.9
TOS 2 Obsession 2×18 3619.2 – 3620.7 3619.2
TOS 2 The Apple 2×09 3715.0 – 3715.6 3715
TOS 2 Journey to Babel 2×15 3842.3 – 3843.4 3842.3
TOS 2 Bread and Circuses 2×14 4040.7 – 4041.7 4040.7
TAS 1 The Slaver Weapon 1×14 4187.3 4187.3
TOS 2 The Doomsday Machine 2×06 4202.9 4202.9
TOS 2 A Private Little War 2×16 4211.4 – 4211.8 4211.4
TOS 2 The Immunity Syndrome 2×19 4307.1 – 4309.4 4307.1
TOS 3 Elaan of Troyius 3×02 4372.5 4372.5
TOS 3 Spectre of the Gun 3×01 4385.3 4385.3
TOS 2 I, Mudd 2×12 4513.3 4513.3
TOS 2 The Trouble with Tribbles 2×13 4523.3 – 4525.6 4523.3
DS9 5 Trials and Tribble-ations 5×06 4523.7 4523.7
TOS 2 By Any Other Name 2×21 4657.5 – 4658.9 4657.5
TOS 2 The Ultimate Computer 2×24 4729.4 – 4731.3 4729.4
TOS 2 Return to Tomorrow 2×22 4768.3 – 4770.3 4768.3
TOS 3 The Paradise Syndrome 3×03 4842.6 – 4843.6 4842.6
TAS 1 Mudd’s Passion 1×10 4978.5 4978.5
TOS 3 The Enterprise Incident 3×04 5027.3 – 5027.4 5027.3
TOS 3 And the Children Shall Lead 3×05 5029.5 5029.5
TOS 2 A Piece of the Action 2×20 Unknown 5101
TOS 2 Patterns of Force 2×23 Unknown 5102
TOS 2 The Omega Glory 2×25 5103
TOS 2 Assignment: Earth 2×26 Unknown 5104
TOS 1 The City on the Edge of Forever 1×28 Unknown 5105
TOS 2 Mirror, Mirror 2×10 Unknown 5106
TOS 3 Day of the Dove 3×11 Unknown 5108
TOS 3 That Which Survives 3×14 Unknown 5109
TOS 3 The Empath 3×08 5121.5 5121.5
TAS 1 The Survivor 1×06 5143.3 5143.3
TAS 1 Beyond the Farthest Star 1×01 5221.3 – 5221.8 5221.3
TAS 1 The Time Trap 1×12 5267.2 – 5267.6 5267.2
TAS 2 Albatross 2×04 5275.6 – 5276.8 5275.6
TAS 1 One of Our Planets Is Missing 1×03 5371.3 – 5372.1 5371.3
TAS 1 Yesteryear 1×02 5373.4 5373.4
TAS 1 More Tribbles, More Troubles 1×05 5392.4 5392.4
TOS 3 The Mark of Gideon 3×17 5423.4 – 5423.8 5423.4
TOS 3 Spock’s Brain 3×06 5431.4 – 5432.3 5431.4
TOS 3 For the World is Hollow and I Have Touched the Sky 3×10 5476.3 – 5476.4 5476.3
TAS 1 The Lorelei Signal 1×04 5483.7 – 5483.9 5483.7
TAS 1 The Ambergris Element 1×13 5499.9 5499.9
TAS 1 The Eye of the Beholder 1×15 5501.2 5501.2
TAS 1 The Infinite Vulcan 1×07 5554.4 -5554.8 5554.4
TAS 1 The Terratin Incident 1×11 5577.3 – 5577.7 5577.3
TAS 1 Once Upon a Planet 1×09 5591.2 5591.2
TOS 3 Is There in Truth No Beauty? 3×07 5630.7 – 5630.8 5630.7
TAS 1 The Jihad 1×16 5683.1 5683.1
TOS 3 The Tholian Web 3×09 5693.2 5693.2
TOS 3 Wink of an Eye 3×13 5710.5 – 5710.9 5710.5
TOS 3 Whom Gods Destroy 3×16 5718.3 5718.3
TOS 3 The Lights of Zetar 3×18 5725.3 – 5725.6 5725.3
TOS 3 Let That Be Your Last Battlefield 3×15 5730.2 – 5730.7 5730.2
TOS 3 Plato’s Stepchildren 3×12 5784.2 – 5784.3 5784.2
TOS 3 The Cloud Minders 3×19 5818.4 – 5819.3 5818.4
TOS 3 The Way to Eden 3×20 5832.3 – 5832.6 5832.3
TOS 3 Requiem for Methuselah 3×21 5843.7 – 5843.8 5843.7
TOS 3 The Savage Curtain 3×22 5906.4 – 5906.5 5906.4
TOS 3 Turnabout Intruder 3×24 5928.5 – 5930.3 5928.5
TOS 3 All Our Yesterdays 3×23 5943.7 – 5943.9 5943.7
TAS 2 How Sharper Than a Serpent’s Tooth 2×05 6063.4 – 6063.5 6063.4
TAS 2 The Pirates of Orion 2×01 6334.1 – 6335.6 6334.1
TAS 2 The Counter-Clock Incident 2×06 6770.1 – 6770.6 6770.1
TAS 2 Bem 2×02 7403.6 7403.6
MOV Star Trek: The Motion Picture 1 7412.6 7412.6
MOV Star Trek 2: The Wrath of Khan 2 8130.4 8130.4
MOV Star Trek 3: The Search for Spock 3 8210.3 8210.3
MOV Star Trek 4: The Voyage Home 4 8390 8390
MOV Star Trek 5: The Final Frontier 5 8454.1 8454.1
MOV Star Trek 6: The Undiscovered Country 6 9521.6 9521.6
TNG 1 Encounter at Farpoint 1×01/02 41153.7 41153.7
TNG 1 Encounter at Farpoint II 1×01/02 41153.7 41153.7
TNG 1 The Naked Now 1×03 41209.2 41209.2
TNG 1 Code of Honor 1×04 41235.25 41235.25
TNG 1 Datalore 1×13 41242.4 41242.4
TNG 1 Lonely Among Us 1×07 41249.3 41249.3
TNG 1 Justice 1×08 41255.6 41255.6
TNG 1 Where No One Has Gone Before 1×06 41263.1 41263.1
TNG 1 Haven 1×11 41294.5 41294.5
TNG 1 Too Short a Season 1×16 41309.5 41309.5
TNG 1 11001001 1×15 41365.9 41365.9
TNG 1 The Last Outpost 1×05 41386.4 41386.4
TNG 1 Coming of Age 1×19 41461.2 41461.2
TNG 1 Home Soil 1×18 41463.9 41463.9
TNG 1 Heart of Glory 1×20 41503.7 41503.7
TNG 1 When The Bough Breaks 1×17 41509.1 41509.1
TNG 1 Hide and Q 1×10 41590.5 41590.5
TNG 1 Skin of Evil 1×23 41601.3 41601.3
TNG 1 Angel One 1×14 41636.9 41636.9
TNG 1 We’ll Always Have Paris 1×24 41697.9 41697.9
TNG 1 The Battle 1×09 41723.9 41723.9
TNG 1 Conspiracy 1×25 41775.5 41775.5
TNG 1 The Arsenal of Freedom 1×21 41798.2 41798.2
TNG 1 Symbiosis 1×22 Unknown 41800
TNG 1 The Neutral Zone 1×26 41986 41986
TNG 1 The Big Goodbye 1×12 41997.7 41997.7
TNG 2 The Child 2×01 42073.1 42073.1
TNG 2 Where Silence Has Lease 2×02 42193.6 42193.6
TNG 2 Elementary, Dear Data 2×03 42286.3 42286.3
TNG 2 The Outrageous Okona 2×04 42402.7 42402.7
TNG 2 The Schizoid Man 2×06 42437.5 42437.5
TNG 2 Loud As A Whisper 2×05 42477.2 42477.2
TNG 2 Unnatural Selection 2×07 42494.8 42494.8
TNG 2 A Matter Of Honor 2×08 42506.5 42506.5
TNG 2 The Measure Of A Man 2×09 42523.7 42523.7
TNG 2 The Dauphin 2×10 42568.8 42568.8
TNG 2 Contagion 2×11 42609.1 42609.1
TNG 2 The Royale 2×12 42625.4 42625.4
TNG 2 Time Squared 2×13 42679.2 42679.2
TNG 2 The Icarus Factor 2×14 42686.4 42686.4
TNG 2 Pen Pals 2×15 42695.3 42695.3
TNG 2 Q Who 2×16 42761.3 42761.3
TNG 2 Samaritan Snare 2×17 42779.1 42779.1
TNG 2 Up The Long Ladder 2×18 42823.2 42823.3
TNG 2 Manhunt 2×19 42859.2 42859.2
TNG 2 The Emissary 2×20 42901.3 42901.3
TNG 2 Peak Performance 2×21 42923.4 42923.4
TNG 2 Shades of Gray 2×22 42976.1 42976.1
TNG 3 Evolution 3×01 43125.8 43125.8
TNG 3 The Ensigns of Command 3×02 43133.3 43133.3
TNG 3 The Survivors 3×03 43152.4 43152.4
TNG 3 Who Watches The Watchers 3×04 43173.5 43173.5
TNG 3 The Bonding 3×05 43198.7 43198.7
TNG 3 Booby Trap 3×06 43205.6 43205.6
TNG 3 The Enemy 3×07 43349.2 43349.2
TNG 3 The Price 3×08 43385.6 43385.6
TNG 3 The Vengeance Factor 3×09 43421.9 43421.9
TNG 3 The Defector 3×10 43462.5 43462.5
TNG 3 The Hunted 3×11 43489.2 43489.2
TNG 3 The High Ground 3×12 43510.7 43510.7
TNG 3 Deja Q 3×13 43539.1 43539.1
TNG 3 A Matter of Perspective 3×14 43610.4 43610.4
TNG 3 Yesterday’s Enterprise 3×15 43625.2 43625.2
TNG 3 The Offspring 3×16 43657 43657
TNG 3 Sins of the Father 3×17 43685.2 43685.2
TNG 3 Allegiance 3×18 43714.1 43714.1
TNG 3 Captain’s Holiday 3×19 43745.2 43745.2
TNG 3 Tin Man 3×20 43779.3 43779.3
TNG 3 Hollow Pursuits 3×21 43807.4 43807.4
TNG 3 The Most Toys 3×22 43872.2 43872.2
TNG 3 Sarek 3×23 43917.4 43917.4
TNG 3 Ménage à Troi 3×24 43930.7 43930.7
TNG 3 Transfigurations 3×25 43957.2 43957.2
TNG 3 The Best of Both Worlds 3×26 43989.1 43989.1
TNG 4 The Best of Both Worlds, Part II 4×01 44001.4 44001.4
TNG 4 Family 4×02 44012.3 44012.3
TNG 4 Brothers 4×03 44085.7 44085.7
TNG 4 Suddenly Human 4×04 44143.7 44143.7
TNG 4 Remember Me 4×05 44161.2 44161.2
TNG 4 Legacy 4×06 44215.2 44215.2
TNG 4 Reunion 4×07 44246.3 44246.3
TNG 4 Future Imperfect 4×08 44286.5 44286.5
TNG 4 Final Mission 4×09 44307.3 44307.3
TNG 4 The Loss 4×10 44356.9 44356.9
TNG 4 Data’s Day 4×11 44390.1 44390.1
TNG 4 The Wounded 4×12 44429.6 44429.6
TNG 4 Devil’s Due 4×13 44474.5 44474.5
TNG 4 First Contact 4×15 Unknown 44500
TNG 4 Clues 4×14 44502.7 44502.7
TNG 4 Galaxy’s Child 4×16 44614.6 44614.6
TNG 4 Night Terrors 4×17 44631.2 44631.2
TNG 4 Identity Crisis 4×18 44664.5 44664.5
TNG 4 The Nth Degree 4×19 44704.2 44704.2
TNG 4 Qpid 4×20 44741.9 44741.9
TNG 4 The Drumhead 4×21 44769.2 44769.2
TNG 4 Half a Life 4×22 44805.3 44805.3
TNG 4 The Host 4×23 44821.3 44821.3
TNG 4 The Mind’s Eye 4×24 44885.5 44885.5
TNG 4 In Theory 4×25 44932.3 44932.3
TNG 4 Redemption 4×26 44995.3 44995.3
TNG 5 Redemption II 5×01 45020.4 45020.4
TNG 5 Darmok 5×02 45047.2 45047.2
TNG 5 Ensign Ro 5×03 45076.3 45076.3
TNG 5 Silicon Avatar 5×04 45122.3 45122.3
TNG 5 Disaster 5×05 45156.1 45156.1
TNG 5 The Game 5×06 45208.2 45208.2
TNG 5 Unification I 5×07 45236.4 45236.4
TNG 5 Unification II 5×08 45245.8 45245.8
TNG 5 A Matter of Time 5×09 45349.1 45349.1
TNG 5 New Ground 5×10 45376.3 45376.3
TNG 5 Hero Worship 5×11 45397.3 45397.3
TNG 5 Violations 5×12 45429.3 45429.3
TNG 5 The Masterpiece Society 5×13 45470.1 45470.1
TNG 5 Conundrum 5×14 45494.2 45494.2
TNG 5 Power Play 5×15 45571.2 45571.2
TNG 5 Ethics 5×16 45587.3 45587.3
TNG 5 The Outcast 5×17 45614.6 45614.6
TNG 5 Cause and Effect 5×18 45652.1 45652.1
TNG 5 The First Duty 5×19 45703.9 45703.9
TNG 5 Cost of Living 5×20 45733.6 45733.6
TNG 5 The Perfect Mate 5×21 45761.3 45761.3
TNG 5 Imaginary Friend 5×22 45832.1 45832.1
TNG 5 I Borg 5×23 45854.2 45854.2
TNG 5 The Next Phase 5×24 45892.4 45892.4
TNG 5 The Inner Light 5×25 45944.1 45944.1
TNG 5 Time’s Arrow 5×26 45959.1 45959.1
TNG 6 Time’s Arrow, Part II 6×01 46001.3 46001.3
TNG 6 Realm of Fear 6×02 46041.1 46041.1
TNG 6 Man of the People 6×03 46071.6 46071.6
TNG 6 Relics 6×04 46125.3 46125.3
TNG 6 Schisms 6×05 46154.2 46154.2
TNG 6 True Q 6×06 46192.3 46192.3
TNG 6 Rascals 6×07 46235.7 46235.7
TNG 6 A Fistful of Datas 6×08 46271.5 46271.5
TNG 6 The Quality of Life 6×09 46307.2 46307.2
TNG 6 Chain of Command, Part I 6×10 46357.4 46357.4
TNG 6 Chain of Command, Part II 6×11 46360.8 46360.8
DS9 1 Emissary II 1×01/02 46379.1 46379.1
DS9 1 Emissary I 1×01/02 46379.1 46379.1
DS9 1 Past Prologue 1×03 Unknown 46400
DS9 1 A Man Alone 1×04 46421.5 46421.5
DS9 1 Babel 1×05 46423.7 46423.7
TNG 6 Ship in a Bottle 6×12 46424.1 46424.1
TNG 6 Aquiel 6×13 46461.3 46461.3
DS9 1 Captive Pursuit 1×06 46477.5 46477.5
TNG 6 Face of the Enemy 6×14 46519 46519
DS9 1 Q-Less 1×07 46531.2 46531.2
TNG 6 Tapestry 6×15 Unknown 46532
DS9 1 The Passenger 1×09 Unknown 46533
TNG 6 Birthright, Part I 6×16 46578.4 46578.4
TNG 6 Birthright, Part II 6×17 46579.2 46579.2
DS9 1 Move Along Home 1×10 Unknown 46580
DS9 1 The Nagus 1×11 Unknown 46581
TNG 6 Starship Mine 6×18 46682.4 46682.4
TNG 6 Lessons 6×19 46693.1 46693.1
DS9 1 Vortex 1×12 Unknown 46694
DS9 1 Battle Lines 1×13 Unknown 46694
DS9 1 The Storyteller 1×14 46729.1 46729.1
TNG 6 The Chase 6×20 46731.5 46731.5
TNG 6 Frame of Mind 6×21 46778.1 46778.1
TNG 6 Suspicions 6×22 46830.1 46830.1
DS9 1 Progress 1×15 46844.3 46844.3
TNG 6 Rightful Heir 6×23 46852.2 46852.2
DS9 1 If Wishes Were Horses 1×16 46853.2 46853.2
DS9 1 Dax 1×08 46910.1 46910.1
TNG 6 Second Chances 6×24 46915.2 46915.2
DS9 1 Dramatis Personae 1×18 46922.3 46922.3
DS9 1 The Forsaken 1×17 46925.1 46925.1
DS9 1 Duet 1×19 Unknown 46926
TNG 6 Timescape 6×25 46944.2 46944.2
DS9 1 In the Hands of the Prophets 1×20 Unknown 46945
TNG 6 Descent 6×26 46982.1 46982.1
TNG 7 Descent, Part II 7×01 47025.4 47025.4
DS9 2 The Homecoming 2×01 Unknown 47026
DS9 2 The Circle 2×02 Unknown 47027
DS9 2 The Siege 2×03 Unknown 47028
TNG 7 Liaisons 7×02 Unknown 47029
TNG 7 Gambit, Part I 7×04 47135.2 47135.2
TNG 7 Gambit, Part II 7×05 47160.1 47160.1
DS9 2 Cardassians 2×05 47177.2 47177.2
DS9 2 Invasive Procedures 2×04 47182.1 47182.1
TNG 7 Interface 7×03 47215.5 47215.5
TNG 7 Phantasms 7×06 47225.7 47225.7
DS9 2 Melora 2×06 47229.1 47229.1
TNG 7 Dark Page 7×07 47254.1 47254.1
DS9 2 Rules of Acquisition 2×07 Unknown 47255
DS9 2 Necessary Evil 2×08 47282.5-47284.1 47282.5
TNG 7 Attached 7×08 47304.2 47304.2
TNG 7 Force of Nature 7×09 47310.2 47310.2
DS9 2 Second Sight 2×09 47329.4 47329.4
DS9 2 Sanctuary 2×10 47391.2 47391.2
TNG 7 Parallels 7×11 47391.2 47391.2
DS9 2 Rivals 2×11 Unknown 47391.3
DS9 2 The Alternate 2×12 47391.7 47391.7
TNG 7 Inheritance 7×10 47410.2 47410.2
TNG 7 Homeward 7×13 47423.9 47423.9
TNG 7 The Pegasus 7×12 47457.1 47457.1
ENT 4 These Are the Voyages… 4×22 47457.1 47457.1
DS9 2 Armageddon Game 2×13 Unknown 47458
TNG 7 Sub Rosa 7×14 Unknown 47459
TNG 7 Lower Decks 7×15 47566.7 47566.7
DS9 2 Paradise 2×15 47573.1 47573.1
DS9 2 Whispers 2×14 47581.2 47581.2
DS9 2 Shadowplay 2×16 47603.3 47603.3
TNG 7 Thine Own Self 7×16 47611.2 47611.2
TNG 7 Masks 7×17 47615.2 47615.2
DS9 2 Playing God 2×17 Unknown 47616
TNG 7 Eye of the Beholder 7×18 47622.1 47622.1
DS9 2 Profit and Loss 2×18 Unknown 47623
TNG 7 Genesis 7×19 47653.2 47653.2
DS9 2 Blood Oath 2×19 Unknown 47654
TNG 7 Journey’s End 7×20 47751.2 47751.2
DS9 2 The Maquis, Part I 2×20 Unknown 47752
DS9 2 The Maquis, Part II 2×21 Unknown 47753
TNG 7 Firstborn 7×21 47779.4 47779.4
TNG 7 Bloodlines 7×22 47829.1 47829.1
DS9 2 The Wire 2×22 Unknown 47830
TNG 7 Emergence 7×23 47869.2 47869.2
DS9 2 Crossover 2×23 Unknown 47870
TNG 7 Preemptive Strike 7×24 47941.7 47941.7
DS9 2 The Collaborator 2×24 Unknown 47942
DS9 2 Tribunal 2×25 47944.2 47944.2
TNG 7 All Good Things… 7×25/26 47988 47988
DS9 2 The Jem’Hadar 2×26 Unknown 47989
DS9 3 The Search, Part I 3×01 48213.1 48213.1
DS9 3 The Search, Part II 3×02 48217.7 48217.7
DS9 3 The House of Quark 3×03 48224.2 48224.2
DS9 3 Equilibrium 3×04 Unknown 48225
DS9 3 Second Skin 3×05 48244.5 48244.5
DS9 3 The Abandoned 3×06 48301.1 48301.1
VOY 1 Caretaker 1×01/02 48315.6 48315.6
VOY 1 Caretaker II 1×01/02 48315.6 48315.6
DS9 3 Civil Defense 3×07 48388.8 48388.8
DS9 3 Meridian 3×08 48423.2 48423.2
VOY 1 Parallax 1×03 48439.7 48439.7
DS9 3 Defiant 3×09 48467.3 48467.3
DS9 3 Fascination 3×10 Unknown 48468
DS9 3 Past Tense, Part I 3×11 48481.2 48481.2
DS9 3 Past Tense, Part II 3×12 48481.2 48481.2
VOY 1 Time and Again 1×04 Unknown 48482
DS9 3 Life Support 3×13 48498.4 48498.4
DS9 3 Heart of Stone 3×14 48521.5 48521.5
VOY 1 Phage 1×05 48532.4 48532.4
DS9 3 Destiny 3×15 48543.2 48543.2
VOY 1 The Cloud 1×06 48546.2 48546.2
DS9 3 Prophet Motive 3×16 Unknown 48547
DS9 3 Visionary 3×17 48576.7 48576.7
VOY 1 Ex Post Facto 1×08 Unknown 48577
VOY 1 Eye of the Needle 1×07 48579.4 48579.4
DS9 3 Distant Voices 3×18 48592.2 48592.2
MOV 9 Generations 48593
VOY 1 Emanations 1×09 48623.5 48623.5
VOY 1 Prime Factors 1×10 48642.5 48642.5
VOY 1 State of Flux 1×11 48658.2 48658.2
DS9 3 Through the Looking Glass 3×19 Unknown 48659
VOY 1 Heroes and Demons 1×12 48693.2 48693.2
DS9 3 Improbable Cause 3×20 Unknown 48694
DS9 3 The Die is Cast 3×21 Unknown 48695
VOY 1 Cathexis 1×13 48734.2 48734.2
DS9 3 Explorers 3×22 Unknown 48735
VOY 1 Faces 1×14 48784.2 48784.2
DS9 3 Family Business 3×23 Unknown 48789
VOY 1 Jetrel 1×15 48832.1 48832.1
DS9 3 Shakaar 3×24 Unknown 48833
VOY 1 Learning Curve 1×16 48846.5 48846.5
DS9 3 Facets 3×25 48876.3 48876.3
VOY 2 Projections 2×03 48892.1 48892.1
VOY 2 Elogium 2×04 48921.3 48921.3
DS9 3 The Adversary 3×26 48959.1 48959.1
VOY 2 The 37’s 2×01 48975.1 48975.1
VOY 2 Initiations 2×02 49005.3 49005.3
VOY 2 Non Sequitur 2×05 49011 49011
DS9 4 The Way of the Warrior 4×01/02 49011.4 49011.4
VOY 2 Twisted 2×06 Unknown 49012
DS9 4 The Visitor 4×03 49034.7 49034.7
DS9 4 Hippocratic Oath 4×04 49066.5 49066.5
VOY 2 Parturition 2×07 49068.5 49068.5
DS9 4 Indiscretion 4×05 Unknown 49069
VOY 2 Persistence of Vision 2×08 Unknown 49070
VOY 2 Tattoo 2×09 Unknown 49071
VOY 2 Cold Fire 2×10 49164.8 49164.8
DS9 4 Homefront 4×11 49170.65 49170.65
DS9 4 Paradise Lost 4×12 Unknown 49171
VOY 2 Prototype 2×13 Unknown 49172
DS9 4 Rejoined 4×06 49195.5 49195.5
VOY 2 Maneuvers 2×11 49208.5 49208.5
DS9 4 Starship Down 4×07 49263.5 49263.5
DS9 4 Little Green Men 4×08 Unknown 49264
VOY 2 Resistance 2×12 Unknown 49289
DS9 4 The Sword of Kahless 4×09 49289.1 49289.1
DS9 4 Our Man Bashir 4×10 49300.7 49300.7
VOY 2 Death Wish 2×18 49301.2 49301.2
VOY 2 Alliances 2×14 49337.4 49337.4
DS9 4 Crossfire 4×13 Unknown 49338
VOY 2 Threshold 2×15 49373.4 49373.4
DS9 4 Return to Grace 4×14 Unknown 49374
VOY 2 Meld 2×16 Unknown 49375
VOY 2 Dreadnought 2×17 49447 49447
VOY 2 Investigations 2×20 49485.2 49485.2
VOY 2 Lifesigns 2×19 49504.3 49504.3
VOY 2 Deadlock 2×21 49548.7 49548.7
DS9 4 Sons of Mogh 4×15 49556.2 49556.2
DS9 4 Bar Association 4×16 Unknown 49557
DS9 4 Accession 4×17 Unknown 49558
VOY 2 Innocence 2×22 49578.2 49578.2
VOY 2 Tuvix 2×24 49655.2 49655.2
DS9 4 For the Cause 4×22 Unknown 49656
DS9 4 Rules of Engagement 4×18 49665.3 49665.3
DS9 4 Hard Time 4×19 Unknown 49666
DS9 4 Shattered Mirror 4×20 Unknown 49667
VOY 2 The Thaw 2×23 Unknown 49668
DS9 4 The Muse 4×21 Unknown 49669
VOY 2 Resolutions 2×25 49690.1 49690.1
DS9 4 To the Death 4×23 49904.2 49904.2
DS9 4 The Quickening 4×24 Unknown 49905
DS9 4 Body Parts 4×25 49930.3 49930.3
DS9 4 Broken Link 4×26 49962.4 49962.4
VOY 2 Basics, Part I 2×26 Unknown 49963
VOY 3 Basics, Part II 3×01 50032.7 50032.7
DS9 5 Apocalypse Rising 5×01 Unknown 50033
DS9 5 The Ship 5×02 50049.3 50049.3
DS9 5 Looking for par’Mach in All the Wrong Places 5×03 50061.2 50061.2
DS9 5 Nor the Battle to the Strong 5×04 Unknown 50062
DS9 5 The Assignment 5×05 Unknown 50063
VOY 3 False Profits 3×05 50074.3 50074.3
VOY 3 Remember 3×06 50203.1 50074.3
VOY 3 Flashback 3×02 50126.4 50126.4
VOY 3 The Chute 3×03 50156.2 50156.2
VOY 3 Sacred Ground 3×07 50063.2 50203.1
VOY 3 The Swarm 3×04 50252.3 50252.3
VOY 3 Future’s End 3×08 50312.5 50312.5
VOY 3 Future’s End, Part II 3×09 50312.5 50312.5
DS9 5 Let He Who Is Without Sin… 5×07 Unknown 50313
DS9 5 Things Past 5×08 Unknown 50314
VOY 3 Warlord 3×10 50348.1 50348.1
DS9 5 The Ascent 5×09 Unknown 50349
VOY 3 The Q and the Grey 3×11 50384.2 50384.2
DS9 5 Rapture 5×10 Unknown 50385
DS9 5 The Darkness and the Light 5×11 50416.2 50416.2
VOY 3 Macrocosm 3×12 50425.1 50425.1
VOY 3 Fair Trade 3×13 Unknown 50426
VOY 3 Alter Ego 3×14 50460.3 50460.3
DS9 5 The Begotten 5×12 Unknown 50461
DS9 5 For the Uniform 5×13 50485.2 50485.2
VOY 3 Coda 3×15 50518.6 50518.6
VOY 3 Blood Fever 3×16 50537.2 50537.2
MOV 9 First Contact 50538
DS9 5 In Purgatory’s Shadow 5×14 Unknown 50539
DS9 5 By Inferno’s Light 5×15 50564.2 50564.2
VOY 3 Unity 3×17 50614.2 50614.2
VOY 3 Darkling 3×18 50693.2 50693.2
DS9 5 Doctor Bashir, I Presume 5×16 Unknown 50694
VOY 3 Rise 3×19 Unknown 50695
DS9 5 A Simple Investigation 5×17 Unknown 50696
DS9 5 Business as Usual 5×18 Unknown 50697
DS9 5 Ties of Blood and Water 5×19 50712.5 50712.5
VOY 3 Favorite Son 3×20 50732.4 50732.4
DS9 5 Ferengi Love Songs 5×20 Unknown 50733
DS9 5 Soldiers of the Empire 5×21 Unknown 50734
DS9 5 Children of Time 5×22 50814.2 50814.2
VOY 3 Before and After 3×21 Unknown 50815
VOY 3 Distant Origin 3×23 Unknown 50836
VOY 3 Real Life 3×22 50836.2 50836.2
DS9 5 Empok Nor 5×24 50901.7 50901.7
VOY 3 Displaced 3×24 50912.4 50912.4
DS9 5 Blaze of Glory 5×23 Unknown 50913
DS9 5 In the Cards 5×25 50929.4 50929.4
VOY 3 Worst Case Scenario 3×25 50953.4 50953.4
DS9 5 Call to Arms 5×26 50975.2 50975.2
VOY 4 Day of Honor 4×03 Unknown 50976
VOY 3 Scorpion 3×26 50984.3 50984.2
VOY 4 Scorpion, Part II 4×01 51003.7 51003.7
VOY 4 The Gift 4×02 51008 51008
VOY 4 Nemesis 4×04 51082.4 51082.4
DS9 6 Rocks and Shoals 6×02 51096.2 51096.2
DS9 6 Sons and Daughters 6×03 Unknown 51097
DS9 6 Behind the Lines 6×04 51145.3 51145.3
DS9 6 Favor the Bold 6×05 Unknown 51146
DS9 6 Sacrifice of Angels 6×06 Unknown 51147
VOY 4 The Raven 4×06 Unknown 51148
VOY 4 Revulsion 4×05 51186.2 51186.2
DS9 6 A Time to Stand 6×01 Unknown 51187
VOY 4 Scientific Method 4×07 51244.3 51244.3
DS9 6 You Are Cordially Invited 6×07 51247.5 51247.5
VOY 4 Year of Hell 4×08 51268.4 51268.4
VOY 4 Random Thoughts 4×10 51367.2 51367.2
DS9 6 Statistical Probabilities 6×09 Unknown 51368
VOY 4 Concerning Flight 4×11 51386.4 51386.4
DS9 6 The Magnificent Ferengi 6×10 Unknown 51387
DS9 6 Waltz 6×11 51408.6-51413.6 51408.6
DS9 6 Resurrection 6×08 Unknown 51425
VOY 4 Year of Hell, Part II 4×09 51425.4 51425.4
VOY 4 Mortal Coil 4×12 51449.2 51449.2
VOY 4 Message in a Bottle 4×14 51462 51462
VOY 4 Waking Moments 4×13 51471.3 51471.3
DS9 6 Who Mourns for Morn? 6×12 Unknown 51472
DS9 6 Far Beyond the Stars 6×13 Unknown 51473
DS9 6 One Little Ship 6×14 51474.2 51474.2
VOY 4 Hunters 4×15 51501.4 51501.4
DS9 6 Honor Among Thieves 6×15 Unknown 51502
DS9 6 Change of Heart 6×16 51597.2 51597.2
VOY 4 Prey 4×16 51652.3 51652.3
VOY 4 Retrospect 4×17 51658.2 51658.2
VOY 4 The Killing Game 4×18 Unknown 51659
VOY 4 The Killing Game, Part II 4×19 51715.2 51715.2
DS9 6 Wrongs Darker Than Death or Night 6×17 Unknown 51716
DS9 6 Inquisition 6×18 Unknown 51717
DS9 6 In the Pale Moonlight 6×19 51721.3 51721.3
VOY 4 Vis à Vis 4×20 51762.4 51762.4
VOY 4 The Omega Directive 4×21 51781.2 51781.2
DS9 6 His Way 6×20 Unknown 51782
VOY 4 Unforgettable 4×22 51813.4 51813.4
DS9 6 The Reckoning 6×21 Unknown 51814
VOY 4 Living Witness 4×23 Unknown 51815
DS9 6 Valiant 6×22 51825.4 51825.4
VOY 4 Demon 4×24 Unknown 51826
DS9 6 Profit and Lace 6×23 Unknown 51827
VOY 4 One 4×25 51929.3 51929.3
DS9 6 Time’s Orphan 6×24 Unknown 51930
DS9 6 The Sound of Her Voice 6×25 51948.3 51948.3
DS9 6 Tears of the Prophets 6×26 Unknown 51949
VOY 4 Hope and Fear 4×26 51978.2 51978.2
VOY 5 Night 5×01 52081.2 52081.2
VOY 5 Drone 5×02 Unknown 52082
VOY 5 Extreme Risk 5×03 Unknown 52083
VOY 5 In the Flesh 5×04 52136.4 52136.4
VOY 5 Once Upon a Time 5×05 Unknown 52137
VOY 5 Nothing Human 5×08 Unknown 52138
DS9 7 Shadows and Symbols 7×02 52152.6 52152.6
DS9 7 Afterimage 7×03 Unknown 52153
DS9 7 Take Me Out to the Holosuite 7×04 Unknown 52154
DS9 7 Chrysalis 7×05 Unknown 52155
DS9 7 Treachery, Faith and the Great River 7×06 Unknown 52156
DS9 7 Once More Unto the Breach 7×07 Unknown 52157
DS9 7 The Siege of AR-558 7×08 Unknown 52158
VOY 5 Timeless 5×06 52164.3 52164.3
DS9 7 Image in the Sand 7×01 Unknown 52165
VOY 5 Thirty Days 5×09 52179.4 52179.4
DS9 7 Covenant 7×09 Unknown 52180
VOY 5 Infinite Regress 5×07 52356.2 52356.2
VOY 5 Counterpoint 5×10 Unknown 52357
DS9 7 It’s Only a Paper Moon 7×10 Unknown 52358
DS9 7 Prodigal Daughter 7×11 Unknown 52359
VOY 5 Latent Image 5×11 Unknown 52360
VOY 5 Bride of Chaotica! 5×12 Unknown 52361
DS9 7 The Emperor’s New Cloak 7×12 Unknown 52362
VOY 5 Gravity 5×13 52438.9 52438.9
VOY 5 Bliss 5×14 52542.3 52542.3
DS9 7 Chimera 7×14 Unknown 52543.3
VOY 5 The Disease 5×17 Unknown 52544.3
DS9 7 Badda-Bing, Badda-Bang 7×15 Unknown 52545.3
DS9 7 Inter Arma Enim Silent Leges 7×16 Unknown 52546.3
DS9 7 Penumbra 7×17 52576.2 52576.2
DS9 7 ‘Til Death Do Us Part 7×18 Unknown 52577.2
DS9 7 Strange Bedfellows 7×19 Unknown 52578.2
DS9 7 The Changing Face of Evil 7×20 Unknown 52579.2
DS9 7 When It Rains… 7×21 Unknown 52580.2
DS9 7 Tacking Into the Wind 7×22 Unknown 52581.2
VOY 5 Course: Oblivion 5×18 52586.3 52586.3
VOY 5 Dark Frontier 5×15/16 52619.2 52619.2
VOY 5 Dark Frontier II 5×15/16 52619.2 52619.2
VOY 5 The Fight 5×19 Unknown 52620.2
VOY 5 Think Tank 5×20 Unknown 52621.2
DS9 7 Extreme Measures 7×23 52645.7 52645.7
VOY 5 Someone to Watch Over Me 5×22 52648 52648
VOY 5 11:59 5×23 Unknown 52649
DS9 7 Field of Fire 7×13 Unknown 52739
VOY 5 Relativity 5×24 52861.27 52861.27
DS9 7 The Dogs of War 7×24 52861.3 52861.3
VOY 5 Warhead 5×25 Unknown 52862.27
DS9 7 What You Leave Behind I 7×25/26 Unknown 52862.3
VOY 5 Equinox 5×26 Unknown 52863.27
DS9 7 What You Leave Behind II 7×25/26 Unknown 52863.3
VOY 6 Equinox, Part II 6×01 Unknown 52864.27
MOV 9 Insurrection 52864.3
VOY 5 Juggernaut 5×21 Unknown 52865.3
VOY 6 Survival Instinct 6×02 53049.2 53049.2
VOY 6 Barge of the Dead 6×03 Unknown 53050.2
VOY 6 Tinker Tenor Doctor Spy 6×04 Unknown 53051.2
VOY 6 Dragon’s Teeth 6×07 53167.9 53167.9
VOY 6 Alice 6×05 Unknown 53168.9
VOY 6 Riddles 6×06 53263.2 53263.2
VOY 6 One Small Step 6×08 53292.7 53292.7
VOY 6 The Voyager Conspiracy 6×09 53329 53329
VOY 6 Pathfinder 6×10 Unknown 53330
VOY 6 Fair Haven 6×11 Unknown 53331
VOY 6 Tsunkatse 6×15 53447.2 53447.2
VOY 6 Blink of an Eye 6×12 Unknown 53448.2
VOY 6 Virtuoso 6×13 53556.4 53556.4
VOY 6 Collective 6×16 Unknown 53557.4
VOY 6 Memorial 6×14 Unknown 53558.4
VOY 6 Spirit Folk 6×17 Unknown 53559.4
VOY 6 Ashes to Ashes 6×18 53679.4 53679.4
VOY 6 Child’s Play 6×19 Unknown 53680.4
VOY 6 Good Shepherd 6×20 53753.2 53753.2
VOY 6 Fury 6×23 Unknown 53754.2
VOY 6 Live Fast and Prosper 6×21 53849.2 53849.2
VOY 6 Life Line 6×24 Unknown 53850.2
VOY 6 Muse 6×22 53918 53918
VOY 6 The Haunting of Deck Twelve 6×25 Unknown 53919
VOY 6 Unimatrix Zero 6×26 Unknown 53920
VOY 7 Unimatrix Zero, Part II 7×01 54014.4 54014.4
VOY 7 Drive 7×03 54058.6 54058.6
VOY 7 Repression 7×04 54090.4 54090.4
VOY 7 Imperfection 7×02 54129.4 54129.4
VOY 7 Critical Care 7×05 Unknown 54130.4
VOY 7 Inside Man 7×06 54208.3 54208.3
VOY 7 Body and Soul 7×07 54238.3 54238.3
VOY 7 Nightingale 7×08 54274.7 54274.7
VOY 7 Flesh and Blood 7×09/10 54315.3-54337.5 54315.3
VOY 7 Flesh and Blood 7×09/10 54315.3-54337.5 54315.3
VOY 7 Shattered 7×11 Unknown 54316.3
VOY 7 Lineage 7×12 54452.6 54452.6
VOY 7 Repentance 7×13 54474.6 54474.6
VOY 7 Prophecy 7×14 54518.2-54529.8 54518.2
VOY 7 The Void 7×15 54553.4-54562.7 54553.4
VOY 7 Workforce 7×16 54584.3-54608.6 54584.3
VOY 7 Workforce, Part II 7×17 54622.4 54622.4
VOY 7 Human Error 7×18 Unknown 54623.4
VOY 7 Q2 7×19 54704.5 54704.5
VOY 7 Author, Author 7×20 54732.3 54732.3
VOY 7 Friendship One 7×21 54775.4 54775.4
VOY 7 Natural Law 7×22 54827.7 54827.7
VOY 7 Homestead 7×23 54868.6 54868.6
VOY 7 Renaissance Man 7×24 54890.7 54890.7
VOY 7 Endgame I 7×25/26 54973.4 54973.4
VOY 7 Endgame II 7×26 54973.4 54973.4
MOV 9 Nemesis 10 56844

Clifford

I have a strange affinity for attractors, and has had it since graduating highschool, where I got a top grade in the final mathematics examination. That was under the old grading system. And the grade (13) was given to only two students in my high school that year. The examination centered on strange attractors. I’ve have not spend much time on it lateer. But there is a weird beauty in them.

Recently I discovered Clifford Attractors. Take a look at this page for some very nice examples. They look stunning, and are simple to handle. Lets play with them!

Clifford Attractors are defined by iteratively making these calculations: xn+1 <- sin(ayn) + ccos(axn) yn+1 <- sin(bxn) + dcos(b*yn)

Choose a, b, c and d between -2 and 2. Calculate x,y for n=0 to n=10.000.000 and plot them. It looks cool!

Lets begin by defining a function that takes four variables and a number of points, and calculate the points:

calcTrace <- function(a,b,c,d,numint){
  x <- y <- rep(NULL, numint) # initializing the vectors
  x[1] <- 0 # set the first point to (0,0)
  y[1] <- 0
  for (i in 2:numint){    # calculate the following points
    x[i] <- sin(a*y[(i-1)]) + c*cos(a*x[(i-1)])
    y[i] <- sin(b*x[(i-1)]) + d*cos(b*y[(i-1)])  
  }
  df <- data.frame(x=x,y=y)
  return(df)
}

Lets also define some parameters. I would prefer to choose the parameters at random. But there are a surprising number of instances where this lead to nothing. The formulas converges very quickly on just a few values, and I end up with a simple dot on the plot. I guess that is to be expected – but not what I am looking for. I want beautiful images!

a <- -1.8 
b <- -1.9 
c <- -1.7
d <-  1.9

points <- calcTrace(a,b,c,d,10000000)

That takes some time – I’ll get back to that. Lets plot it. I remove almost anything from the ggplot theme, and insert the parameters in the plot.

library(ggplot2)
opt = theme(legend.position  = "none",
            panel.background = element_rect(fill="white"),
            axis.ticks       = element_blank(),
            panel.grid       = element_blank(),
            axis.title       = element_blank(),
            axis.text        = element_blank(),
            plot.title       = element_text(size=9, face="italic", hjust = 0.5)
            )

p <- ggplot(points, aes(x, y)) + geom_point(color="black", shape=46, alpha=.01) + 
  opt +
  ggtitle(paste("a = ",a , ", b = ", b, "\n c = ", c, " d = ",  d))
print(p)

All right. It takes some time to do the calculations. There are ways to speed that up.

One way is to compile the function.

library(compiler)
compiled <- cmpfun(calcTrace)

According to the compiler packages, that should make the function faster. Lets test it:

library(microbenchmark) 
test <- microbenchmark(
    calcTrace(a,b,c,d,10000000),
    compiled(a,b,c,d,10000000) , times=3
)
print(test)

I am not impressed. This result might be caused by the fact that I am running Paperclips http://www.decisionproblem.com/paperclips in the background (almost ready to release the hypnodrones!) on a not particularly powerfull laptop.

What else could be done? I’m tinkering with this to hone my R-skills. But here might be a situation where it would be better to do it in another language.

The library Rcpp allows me to add C++ code. Lets try that:

library(Rcpp)
cppFunction('DataFrame cppTrace(double a, double b, double c, double d, int numint) {
            // create the columns
            NumericVector x(numint);
            NumericVector y(numint);
            x[0]=0;
            y[0]=0;
            for(int i = 1; i < numint; ++i) {
            x[i] = sin(a*y[i-1])+c*cos(a*x[i-1]);
            y[i] = sin(b*x[i-1])+d*cos(b*y[i-1]);
            }
            // return a new data frame
            return DataFrame::create(_["x"]= x, _["y"]= y);
            }
            ')

Lets see how quick that version is:

library(microbenchmark)
## Loading required package: microbenchmarkCore
test2 <- microbenchmark(
    cppTrace(a,b,c,d,10000000),
    times=3
)
print(test2)
## Unit: seconds
##                         expr     min       lq     mean   median       uq
##  cppTrace(a, b, c, d, 1e+07) 2.11005 2.122835 2.154553 2.135619 2.176804
##       max neval
##  2.217989     3

That was fast!

The plot still takes an awfull lot of time. I have not found a way to do anything about that.

Lets make a new plot, with different parameters.

a <-  1.7
b <-  1.7
c <-  0.7
d <-  1.3
points <- cppTrace(a,b,c,d,10000000)
q <- ggplot(points, aes(x, y)) + geom_point(color="orange", shape=46, alpha=.01) + 
  opt +
  ggtitle(paste("a = ",a , ", b = ", b, "\n c = ", c, " d = ",  d))
print(q)

Nice. Lets make one in green as well:

a <-  -1.6
b <-  1.2
c <-  0.1
d <-  -1.2
points <- cppTrace(a,b,c,d,10000000)
r <- ggplot(points, aes(x, y)) + geom_point(color="green", shape=46, alpha=.01) + 
  opt +
  ggtitle(paste("a = ",a , ", b = ", b, "\n c = ", c, " d = ",  d))
print(r)

 

How do you gauge a place to work

I’ve recently been involved in the recruitment of a mid-level manager in an organization I’m involved with. That got me thinking (always a good way to prepare for anything):

What questions are reasonable to ask? There are rules of course, but what kind of questions is it OK for the prospective new employee to ask.

There are all the professional questions. But you should also be interested in what kind of a workplace you are potentially entering.

I think a good question is: What kind of employee benefits do you offer? And why those?

The added question is important. I am not interested in knowing that you offer all the fruit I can eat. That is not what will decide if I want to take the job.

But it does make a difference if company A offers free coffee. And company B offers me all the water and electricity I will need to brew coffee on the brewer I have to bring myself, using coffee grounds that I will have to buy myself.

And it would be interesting to hear a manager reflect on why they offer free yoga, coffee or whatever.

I think it says a lot about how employees are viewed in a company.

Merging pdf-files

You may need to merge several pdf-files into one.

There are several tools. Some of them you have to pay for.

If you are in a linux environment, try this:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=final.pdf filea.pdf fileb.pdf

continue with filec.pdf etc.

Some say it is slow.

Others say, yes it is slow, but it produces smaller final files, and are able to handle “difficult pdfs”.

I say it is nice that it can be done from the command line.

Visualizing Pi

We celebrate Pi-day (3/14) every year at the library. And though it is december, and there is months to the big day, it is not too early to begin planning. This is something we do in the incredibly amounts of time we have left over when all the other tasks that also only take a tiny portion of the day are done. In other words, this is something we plan in our weekly lunchbreak.

Usually Henrik delivers a small talk about Pi. We eat some Pie, and there is much rejoicing.

But we would like to show something else. A cool visualization perhaps. There are several out there, but it is no fun just to show cool stuff. Its much cooler to understand how it is done.

One of the visualizaions we found on the net is this. https://www.visualcinnamon.com/portfolio/the-art-in-pi It is made by the extremely talented Nadieh Bremer. Take a look at her page. She does a lot of other cool stuff!

So. How to replicate this?

The idea is to take pi. Draw a line segment from 0,0 in the plane to a new point, determined by the first digit. Then we draw another segment from that point, to a newer point, determined by the second digit in Pi. Continue ad nauseam, or until your computer catches fire. Add colours, and make it look cool.

First item is to get pi to a million decimal places. Read it in, and make a vector containing all the digits. I’ll begin with a smaller string.

testnumvec <- "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"

Not quite pi. But I can’t be bothered figuring out how many digits of pi I should use in order to get all the digits from 0 to 9. I want that to make sure that whatever I do, works on all the digits.

Next up is getting rid of the period.

numvec <- gsub("[[:punct:]]", "", testnumvec)

In Denmark we would use a “,” instead of “.” This removes all punctuation.

Now we convert it to a vector with individual digits. And cast them as integers rather than characters.

numvec <- as.integer(unlist(strsplit(numvec,"")))

We begin a (0,0). The next point is determined by the first digit i pi – 3. The number 3 should determine witch direction, angle, we should move. The new x-value will be cos(f(3)), where f(3) is some function, that converts 3 to the correct angle. That should be some fraction of pi. The new y-value is similarly determined by sin(f(3)).

What should f(x) be? Imagine a decimal clock, with the ten digits 0 to 9 positioned around the circle. In the original 0 is at top, at 12 o’clock. 5 is at 6 o’clock. And the numbers follow the circle clockwise. In the unity circle 0 is positioned at 1/2pi. 5 at 1 1/2 pi. So f(0)=1/2pi, f(5)=1 1/2pi.

This formula gives us the result we need: 5/2pi – z/5pi.

z is the digit in pi. For all of them, we can calculate the steps we need in this way:

x <- cos(5/2*pi - numvec/5*pi)
y <- sin(5/2*pi - numvec/5*pi)

So. Beginning at (x0,y0), we calculate the trig functions, add it to (x0,y0) and get (x1,y1). When we continue to do that, we notice, that xi is the cumulative sum of all the calculated x-values. If we calculate the trig functions for all of the digits in pi, and then calculate the cumulative sum, we get all the x-values. Similarly with all the y-values.

Thats neat, and thanks to Henrik, who pointed this out. We get the cumulative sums easily: And we can then get the cumulative sums with:

x <- cumsum(x)
y <- cumsum(y)

Thats it! There is just a little detail. The first value in x,y is the first step we need to take – or the second point if you will. We will need to add a 0 at the start:

x <- c(0,x)
y <- c(0,y)

Thats it! I should now be able to plot it. Lets just do a quick test:

plot(x,y, type="l")

That looks almost like what we need. The most notable difference is that Nadieh only plots the decimals. I include the “3” as well. We are going to test this, and it is cumbersome to do all the preceding steps. Let’s begin with defining the generation of points as a function, that takes a string. In just a little while I’ll invoke the magick of ggplot. So it would be convenient that the result is a dataframe:

piPoints <- function(piString){
  numbers <- gsub("[[:punct:]]", "", piString)
  numbers <- as.integer(unlist(strsplit(numbers,"")))
  x <- cos(5/2*pi - numbers/5*pi)
  y <- sin(5/2*pi - numbers/5*pi)
  x <- cumsum(x)
  y <- cumsum(y)
  x <- c(0,x)
  y <- c(0,y)
  df <- data.frame(as.integer(c(0,numbers)),x,y)
  colnames(df) <- c("num", "x", "y")
  return(df)
}

All right. We now have a dataframe with three columns. The number, and the x,y coordinates. We can plot that with ggplot:

df <- piPoints(testnumvec)
library(ggplot2)

ggplot(df, aes(x=x,y=y,group="1"))+
  geom_path(aes(colour=factor(df$num)))

Weird. Something is wrong. Look at the second linesegment. It goes up and to the right, just as it should, since this segment represents a “1”. But the color? It is green. It should be sorta orangy. The reason is that ggplot looks at the number, and by implication the color, at the origin of the linesegment. Not at the end. How to change that? What I really need to do, is shifting the number column one place relative to the x,y pairs. Simply done – remove the 0 at the beginning of the num-vector in the function. And the final digits in the x and y vectors. I really don’t like it, as it increases the size of the dataframe – but I add an id-column as well. Just a sequential number, to control the colouring:

piPoints <- function(piString){
  numbers <- gsub("[[:punct:]]", "", piString)
  numbers <- as.integer(unlist(strsplit(numbers,"")))
  x <- cos(5/2*pi - numbers/5*pi)
  y <- sin(5/2*pi - numbers/5*pi)
  x <- cumsum(x)
  y <- cumsum(y)
  x <- c(0,x)
  y <- c(0,y)
  id <- 1:(length(y)-1)
  df <- data.frame(as.integer(c(numbers)),x[-length(x)],y[-length(y)], id)
  colnames(df) <- c("num", "x", "y", "id")
  return(df)
}

Lets take another look:

df <- piPoints(testnumvec)
library(ggplot2)

ggplot(df, aes(x=x,y=y,group="1"))+
  geom_path(aes(colour=factor(df$num)))

Now we’re there. Two steps are missing: Adding more digits – I would like to get to one million digits. And getting it to look nice.

Lets try getting to the million. I don’t need to calculate pi to a million decimals. I can just download it.

library(readr)
storpi <- read_file("pi_dec_1m.txt")

df <- piPoints(storpi)
library(ggplot2)

ggplot(df, aes(x=x,y=y,group="1"))+
geom_path(aes(colour=df$id)) +
  scale_colour_gradient(low="red", high="green")

Lets beautify it at bit. theme_bw removes the horrible grey background. coord_fixed(ratio=1) controls the aspect-ratio of the plot. Not really necessary, but in just a short while I’ll expand to other numbers, and would like to compare stuff. And in theme() a lot of stuff is set to blank – we need a clean plot. Finally – or not quite, I change the colours. http://colorbrewer2.org/ helps with choosing colours. Its targeted at maps. But this is a kind of map. I am, more or less working with continous data. So instead of scale_colour_brewer, I use scale_colour_distiller. It’s not quite kosher to use a qualitative scale for this kind of data. But I like the colours, and I really need help choosing them, since I am not a talented designer.

ggplot(df, aes(x=x,y=y,group="1"))+
geom_path(aes(colour=df$id)) +
  scale_colour_distiller(type="qual", palette="Set1") +
    theme_bw() + 
  coord_fixed(ratio = 1) +
  theme(line = element_blank(),
        text = element_blank(),
        title = element_blank(),
        legend.position="none",
        panel.border = element_blank(),
        panel.background = element_blank())
## Warning: Using a discrete colour palette in a continuous scale.
##   Consider using type = "seq" or type = "div" instead

Done!

Whats next?

So. I’ve done pi to a million decimal places. What about other fundamental mathematical constants?. Some of these perhaps? * Square root of 2 (Sqrt(2)) * Square root of 3 (Sqrt(3)) * Golden ratio * e * Natural logarithm of 2 (Log(2)) * Natural logarithm of 3 (Log(3)) * Natural logarithm of 10 (Log(10)) * Apéry’s constant (Zeta(3)) * Lemniscate constant (Lemniscate) * Catalan’s constant (Catalan) * Euler-Mascheroni constant (Euler’s Constant)

And why only a million places? Why not go to a billon?

I feel the need. The need for speed

This is the writeup. So I did all this, without looking at the original code. In the original, the cumulative sums are calculated differently:

x <- y <- rep(NULL, length(numvec))
x[1] <- 0
y[1] <- 0

for (i in 2:length(piVec)){
    x[i] <- x[(i-1)] + sin((pi*2)*(numvec[i]/10))
    y[i] <- y[(i-1)] + cos((pi*2)*(numvec[i]/10))  
}

That is nice. It was also the way I tried to do it. I got lost in apply-functions using lag(). That was definitely not the way to do it.

But is my way faster? I would guess it is, as for-loops in general are not very fast in R. Guessing is not good enough, I need hard data. The way to get it is by measuring the time used. There are several tools for that, and I’ll use microbenchmark, since it provides a neat plot.

You will probably need to install it:

devtools::install_github("olafmersmann/microbenchmarkCore")
devtools::install_github("olafmersmann/microbenchmark")

Lets run the test.

library(microbenchmark)
## Loading required package: microbenchmarkCore
testnumvec <- read_file("pi_dec_1m.txt")
numbers <- gsub("[[:punct:]]", "", testnumvec)
  numbers <- as.integer(unlist(strsplit(numbers,"")))  
numvec <- numbers
mbm <- microbenchmark({
x <- cos(5/2*pi - numvec/5*pi)
y <- sin(5/2*pi - numvec/5*pi)
x <- cumsum(x)
y <- cumsum(y)
x <- c(0,x)
y <- c(0,y)
},{
x <- y <- rep(NULL, length(numvec))
x[1] <- 0
y[1] <- 0
for (i in 2:length(numvec)){
    x[i] <- x[(i-1)] + sin((pi*2)*(numvec[i]/10))
    y[i] <- y[(i-1)] + cos((pi*2)*(numvec[i]/10))  
}
}, times=3

)
levels(mbm$expr) <- c("My way", "Original way")
mbm
## Unit: milliseconds
##          expr       min        lq      mean   median        uq       max
##        My way  177.0869  182.5159  189.8857  187.945  196.2851  204.6253
##  Original way 1677.8690 1721.3408 1787.1957 1764.813 1841.8591 1918.9056
##  neval cld
##      3  a 
##      3   b
autoplot(mbm)

Thats kinda faster. Not that it makes that much of a difference – “My” method does the one million digits in 0.2 seconds. The original takes a little over 9 times as long. Who cares? You are only going to do it once. 2 seconds is not a problem. I would however like to make the same plot with a billion digits. I’m not sure I’ll even be able to plot it. But a naive guess implies that 1.000 times the number of digits will take 200 seconds, or a little more than 3 minutes to run through. 9 times that is almost half an hour. That is a difference you will notice.

Cute Animals – the initial thoughts.

The internet is really a cat-picture delivery system. One thing I have observed on twitter, is that images of cute kittens, in a library setting, receives a LOT of attention. Retweets, likes, all those endorphin inducing things.

Images of cute puppies give the same results. But I have the distinct impression, that people prefer cute kittens over puppies. That, however, is anecdotal evidence. Is there a way to measure it?

What we are interested in is the number of impressions. That is available from analytics.twitter.com. But-but-but. If the puppy-tweet is from november 1st and the kitten-tweet is from december 1st. And I am collecting the impressions on december 2nd, that wont give me a fair comparison. The puppy will have had far longer to collect impressions than the kitten. What I need, is to follow the interactions with the two tweets over time.

A problem with this is, that the twitter API does not give me access to those numbers. I will need another way to get them. I have written a Python script, that collect the csv-files from Twitter analytics for a number of months back. It can be found on my github page. Basically I use the Selenium package to let Python control a browser, that automagically download the statistics. If I do that once every hour, I will be able to graph the number of interactions over time.

I would like a rather comprehensive set of data. Not only kitties and puppies, but also cute hedgehodges, kangaroos etc. It would also be interesting to see if the time the tweet is made makes a difference. And just a single tweet of a cat is not a lot, there should probably be several tweets with each species. We are talking quite a lot of tweets. And quite a lot of data.

I am going to use a google spreadsheet as the backend. That will make it possible to graph the results as they come in.

One thing to consider working with Google Spreadsheets, is the inherent limitations. A workbook has an upper limit of 2.000.000 cells. I am going to gather rather a lot of data.

A quick back-of-envelope calculation:

Once every hour, I am going to download statistics for five months. I probably wont tweet more than 150 times pr month. And I am going to do this for three months, with an average of 30 days in each month. And 24 hours in every day. And for each tweet, I am going to collect 14 variables.

That results in: 14*24*30*3*150*5 = 22.680.000

A bit to much. How to reduce that? First of all, not every tweet I make will be relevant. I am still going to tweet about the benefits of reading instructions before deciding that you can’t figure out how to do something. If I only collect the tweets relevant to this study, it will greatly reduce the amount of data. In the above calculation I collect information on a total of 450 tweets. I will probably only need data on 30 tweets pr month. What also helps, is that the first day, I will get 24 data points on one tweet. On day two, I will get 24 datapoints on two tweets etc. That will probably save me.

The steps will be as follows:

  • Locate a suitable collection of images of cute animals in a library setting.
  • Plan when to tweet them – take into consideration the time of the tweets.
  • Collect – regularly – the data as pr the scripts mentioned above
  • Analyse the data.

 

Tid til en ny nedtælling

Der har været nogen optællinger. Nu tæller vi ned. Der sker noget glædeligt. Noget er slut. Sådan ca. pr. midnat nytårsaften. Det sker noget andet. Det er ikke sikkert at det er bedre. Men dog er det en glædelig begivenhed.

weeks
-45
-2
days
0
-4
hours
0
-7
minutes
-5
-5
seconds
-5
-5

Stress. Depression. Help.

Just a simple point:

If you get stressed to the point of spending time in the restroom crying, get help. Please. And do it now. Not a year after your call for help was ignored. Now. Right now.

Severe stress can lead to depressions. Stress in itself can be crippling. Depression is even worse.

Learn to recognize the signs. Not just in yourself. Also in your colleagues. If you are a manager it might be a good idea to learn about them as well.

And remember, it is not your fault that you get a stress induced depression. You may be expected to take the blame for being stressed. You may be expected to keep soldiering on until you break.

But no one is ever going to thank you for it.

Ever.

Those civil war monuments in the US

I once saw a video suggesting that the US should choose Canada as their next president. They would solve the race-problem. As soon as they figured out why there still was a race-problem. It’s one of those things that are pretty hard to understand for europeans. And apparently for canadians as well.

Anyway, there is a problem, and lately it’s been manifesting in protests against monuments celebrating confederate war-“heroes”. Thats another thing that is difficult to understand from across the atlantic. Those monuments must certainly have been standing there for a very long time. After all, the war ended in 1865. They may be celebrating the losers, but seriously, what’s the problem? Well… Actually there is a problem. Most of the monuments were not erected to commemorate fallen soldiers just after the war. They were erected to show those n******, who was still in charge when they started to organize for rights. And again when those rights were granted (to some degree). There’s a lot more information in this report. And suddenly even europeans begin to understand what all the fuss is about. But still. Seriously? Get over it, you lost, be nice, and treat people like, you know, Jesus said you should.

Okay – that was the introduction. And now for the data. Somewhere in there, there is an interesting datavisualization. The data is here:

https://data.world/datadanlarson/confederatemonument/workspace/file?filename=CivilWarMamorials.csv

What do I want to do with it? I want an animated GIF. Each frame in that gif should represent a year, and show a map of the US, with all the monuments erected up to and including that year. Preferably it should be noticable what monuments where erected that year. A graph showing the development of the number of monuments would be nice as well.

Okay, lets get coding. The data comes from data.world, and they have their own R-package:

  devtools::install_github("datadotworld/data.world-r", build_vignettes = TRUE, force = TRUE)

In order to get to the data, You will need a token. There is excellent help to get at data.world.

data.world::set_config(data.world::save_config(auth_token = "redacted"))

It is a horrible token. Anyway, lets plod on. Load their library, and get the data

library(data.world)
dataset_key <- "https://data.world/datadanlarson/confederatemonument"
tables_qry <- data.world::qry_sql("SELECT * FROM Tables")
tables_df <- data.world::query(tables_qry, dataset = dataset_key)
sample_qry <- data.world::qry_sql(sprintf("SELECT * FROM `%s`", tables_df$tableName[[1]]))
sample_df <- data.world::query(sample_qry, dataset = dataset_key)

This is a simple copy-paste from the examples at data.world. The net result is, that we have all the data in the dataframe sample_df.

We are interested in the year a monument was erected. Not all years are known. And this is of course a serious flaw in the following visualization. Patterns may not be what they appear, when approx. half the data is missing.

Anyway, lets get rid of the rows with missing data:

newdata <- sample_df[complete.cases(sample_df),]

complete.cases returns a logical vector. True if the row is free from NAs, eg. is complete, False if there is an NA in it. newdata is now a dataframe with only the complete cases.

We need coordinates. Google is our friend, however, I’m not going to run that geocoding again. Google allows 2500 calls to their API every day from a given IP-number. It is easy to run out of calls.

library(ggmap)
newerdata <- data.frame(city=character(), state = character(), year = numeric(), status = character(), lat = numeric(), lon = numeric(), stringsAsFactors = FALSE)
for (row in 1:nrow(newdata)){
result <- geocode(paste(newdata[row,2]$city, newdata[row,1]$state, sep=", "), output="latlon", source="google")

    newerdata[nrow(newerdata) + 1,] = c(newdata[row,2]$city,newdata[row,1]$state, as.numeric(newdata[row,5]$year), newdata[row,6]$civilwarstatus, result$lat, result$lon)
  
}
save(newerdata, file="newestdata.rda")

What happens? We call ggmap, which provides the function geocode. A new dataframe, newerdata, is defined. For each row in newdata, I call geogode on the city and state, separated with a “,”, and saves the result in “result”. And then I add the rows I want to the newerdata dataframe. There is probably a better way to do that. But it works. Here there is another thing that should probably be handled. Sometimes Google is not able to determine exactly what location we give it. There may be more than one place in a US state with the same name. I’m just taking the first result google gives me. A bit sloppy, I know. make some plots.

Finally I save the data. Now we should be ready to We are going to need some libraries for that:

library(grid)
library(gganimate)
library(animation)
library(ggplot2)
require(cowplot)

I’ll just make absolutely sure that the data is in the form I need it to be:

load("newestdata.rda")
newestdata <- newestdata[complete.cases(newestdata),]
newestdata <- na.omit(newestdata)
newestdata$year <- as.numeric(newestdata$year)
newestdata$lat <- as.numeric(newestdata$lat)
newestdata$lon <- as.numeric(newestdata$lon)

The coordinates and the year should be numeric. Any rows with missing values should be gone forever.

I get a map to plot on:

us <- get_map("USA", zoom = 4)

And, lets make the first plot:

g <-ggmap(us) +
  geom_point(aes(x=lon, y=lat), data=newestdata, color="red")
g

Theres a lot of red there. I would like to make an animation. The standard way to do it here, or at least the way I usually do it, would be to define a function, that plots what I want to plot as a function of the year. Like this:

singleyear <- function(ye){
  g <-ggmap(us) +
  geom_point(aes(x=lon, y=lat), data=newestdata[which(newestdata$year<(ye)),], color="red")
 g
}

Now, when I make this function call, I should get a map with all the monuments erected before 1890:

singleyear(1890)

I’m missing the monuments erected in 1890. That is because I would like those to be a different color. Lets add to the function, and call it again:

 

 

 

singleyear <- function(ye){
  g <-ggmap(us) +
  geom_point(aes(x=lon, y=lat), data=newestdata[which(newestdata$year<ye),], color="red")+
  geom_point(aes(x=lon, y=lat), data=newestdata[which(newestdata$year==ye),], color="blue")
 g
}
singleyear(1890)

Now, when I plot the map for a given year, all monuments from that year will appear as blue. And for the next year they’ll turn red.

 

 

Lets back up a bit here.

What I’m doing is this: I take the map I retrieved from Google, and plots it with the ggmap function. Then I add points with the geom_point function. I tell the function that the data is “newestdata”, and that the points should be placed at position x,y where x is the longitude, and y the latitude. The color should be red. I am however also telling that the data should be the part of newestdata, where year is smaller than the ye-value I provide to the function. In the next line, I add the same point, just for the part of the data where year is equal to the ye-value i provide to the function. And that the color should be blue.

What I am going to do later, is to call this function for all years from 1860 to 2017, and show those plots one after another. We will get at small movie, where new monuments turn up as blue spots. And then turn red in the next frame.

Everything becomes very red. One way to do something about this, would be to make the dots transparent. Let them fade out. When the monument is just erected, let the dot be blue. The year after, let it be a transparent red dot, the year after that, make it more transparent. Areas with a lot of monuments will still be pretty red, but the new monuments will be more visible. We’ll get at sort of heatmap, where the very red areas are places with at lot of monuments, and the not so red areas have fewer.

I’ll need to have a maximum and a minimum for the transparency. Defined as af function of the year I am plotting, and the year a monument was erected. I’m gonna add it to the dataframe before I plot it. This is the line:

maxp <- 0.8
minp <- 0.3
newestdata$alpha <- (maxp - minp)/(ye-1861)*(as.numeric(newestdata$year)-ye)+maxp

A new column, alpha, is added to the dataframe, and the difference between the year I am plotting, and the year of the row is normalised to the range 0.3 to 0.8. The point begins as blue, turns red with a transparency of 0.8, and will fade to 0.3.

I’m not sure the range is perfect. I’m gonna go with it for now.

Lets add it to the function:

maxp <- 0.8
minp <- 0.3
singleyear <- function(ye){
  newestdata$alpha <- (maxp - minp)/(ye-1861)*(as.numeric(newestdata$year)-ye)+maxp
  g <-ggmap(us) +
    geom_point(aes(x=lon, y=lat), data=newestdata[which(newestdata$year<ye),], alpha=newestdata[which(newestdata$year<ye),]$alpha, color="red")+ 
  geom_point(aes(x=lon, y=lat), data=newestdata[which(newestdata$year==ye),], alpha=1, color="blue")
 g
}
singleyear(1890)

 

What I also added, was this: “alpha=newestdata[which(newestdata$year<(aar)),]$alpha”. Alpha is the transparency. So each point is plottet with the transparency I calculated.

What next? Lets adjust the plot a bit:

maxp <- 0.8
minp <- 0.3
singleyear <- function(ye){
  newestdata$alpha <- (maxp - minp)/(ye-1861)*(as.numeric(newestdata$year)-ye)+maxp
  g <-ggmap(us) +
    geom_point(aes(x=lon, y=lat), data=newestdata[which(newestdata$year<ye),], alpha=newestdata[which(newestdata$year<ye),]$alpha, color="red")+ 
    geom_point(aes(x=lon, y=lat), data=newestdata[which(newestdata$year==ye),], alpha=1, color="blue") +
    theme(plot.title=element_text(hjust=0)) +
    theme(axis.ticks = element_blank(),
        axis.text = element_blank(),
        panel.border = element_blank()) +
    labs(title="Confederate memorials", subtitle=ye, x=" ", y="")
 g
}
singleyear(1890)

 

Labels are left aligned (hjust=0), tickmarks and text is removed (all the element_blank parts). And a title “Confederate memorials” is added, with a subtitle indicating the year we have reached in the plot.

Nice. What more? The interesting part, at least I think it is interesting, is the fact that the number of these memorials increase at certain times. That can be seen on the map. But a line-plot would probably make it more visible. It would also be nice to have it side-by-side with the map. How to do that?

To begin with, I’ll need a set of data with the cumulative count of monuments:

linedata <- as.data.frame(table(newestdata$year), stringsAsFactors = FALSE)

colnames(linedata) <- c("year", "cumsum")
linedata$year <- as.numeric(linedata$year)
linedata$cumsum <- cumsum(linedata$cumsum)

I make a new dataframe, linedata. The content is table(newestdata$year). The table function summarizes the data in newestdata. It gives me a table with all the years, and the number those years occur. Eg. that there are 7 occurences of the year 1870. That corresponds to 7 monuments erected in 1870. I save that as a dataframe. Then I change the names of the colums, and make sure that the years are saved as numeric. And then I call cumsum. That is a function that calculates the cumulative sum. Ie in 1861 2 monuments where erected. None where erected before that. The cumulative sum of all monuments until 1861 was 2. In 1862 3 monuments were erected. The cumulative sum for 1862 is 5. The sum of the 3 monuments erected that year, and all the monuments erected before that.

That in itself is an interesting plot:

ye = 2017
h <- ggplot(linedata[which(linedata$year<=ye),]) +
  geom_line(aes(x=year, y=cumsum))
h

 

Something happens in 1910 and again in 1950. Or somewhere close to those years. At least that is where the graph changes shape.

Lets adjust it a bit:

ye=2017
h <- ggplot(linedata[which(linedata$year<=ye),]) +
  geom_line(aes(x=year, y=cumsum))+
  xlim(1860,2017) +
  ylim(0,850) +
  ylab("Number of confederate memorials") +
  xlab("")
h

Nothing fancy, just freezing the axes, adding a label for the y-axis, and removing it from the x-axis.

Now I can add it to the original plot. I loaded the library cowplot earlier. That gives us the function plot_grid.

 

i <- plot_grid(g,h,align='h')
i

I have two plots, g and h, and combine them in a newplot, horizontally (thats the h in align), to a new plot i. And then I plot i.

 

 

Lets add that to the function:

singleyear <- function(ye){
  newestdata$alpha <- (maxp - minp)/(ye-1861)*(as.numeric(newestdata$year)-ye)+maxp
  g <-ggmap(us) +
    geom_point(aes(x=lon, y=lat), data=newestdata[which(newestdata$year<ye),], alpha=newestdata[which(newestdata$year<ye),]$alpha, color="red")+ 
    geom_point(aes(x=lon, y=lat), data=newestdata[which(newestdata$year==ye),], alpha=1, color="blue") +
    theme(plot.title=element_text(hjust=0)) +
    theme(axis.ticks = element_blank(),
        axis.text = element_blank(),
        panel.border = element_blank()) +
    labs(title="Confederate memorials", subtitle=ye, x=" ", y="")
  h <- ggplot(linedata[which(linedata$year<=ye),]) +
    geom_line(aes(x=year, y=cumsum))+
    xlim(1860,2017) +
    ylim(0,850) +
    ylab("Number of confederate memorials") +
    xlab("")
  i <- plot_grid(g,h,align='h')
  i
}
singleyear(1890)

Now I’m getting there! Almost ready for the animation. I would like some annotation on the h-plot. A couple of arrows. And I would like them to show up in the animation. As in, from year 1910 there should be text at a certain place. But not before. It’s not that difficult.

If I add this:

if(ye>1908){

h <- h + annotate(“text”, x =1980, y = 200, label=“NAACP established”) + geom_segment(aes(x=1950, y = 200, xend=1909, yend = 200), size=1, arrow=arrow(length=unit(0.5, “cm”))) }

to the function, every plot, for a year after 1908, will have an annotation on the h-plot, at position 1980,200, with the text “NAACP established”. The next line, geom_segment, will add an arrow, with a size defined by the size and length parameters, beginning at 1950,200 and ending at 1909,200.

It took quite a bit of time to fiddle with those positions!

That is not the only annotation I want. So the complete function is as follows:

singleyear <- function(ye){
  newestdata$alpha <- (maxp - minp)/(ye-1861)*(as.numeric(newestdata$year)-ye)+maxp
  g <-ggmap(us) +
    geom_point(aes(x=lon, y=lat), data=newestdata[which(newestdata$year<ye),], alpha=newestdata[which(newestdata$year<ye),]$alpha, color="red")+ 
    geom_point(aes(x=lon, y=lat), data=newestdata[which(newestdata$year==ye),], alpha=1, color="blue") +
    theme(plot.title=element_text(hjust=0)) +
    theme(axis.ticks = element_blank(),
        axis.text = element_blank(),
        panel.border = element_blank()) +
    labs(title="Confederate memorials", subtitle=ye, x=" ", y="")
  h <- ggplot(linedata[which(linedata$year<=ye),]) +
    geom_line(aes(x=year, y=cumsum))+
    xlim(1860,2017) +
    ylim(0,850) +
    ylab("Number of confederate memorials") +
    xlab("")
  
  if(ye>1908){
    h <- h + annotate("text", x =1980, y = 200, label="NAACP established") +
       geom_segment(aes(x=1950, y = 200, xend=1909, yend = 200), size=1, arrow=arrow(length=unit(0.5, "cm")))
  }

  if(ye>1910){
    h <- h + annotate("text", x = 1870, y = 500, label="Coincidence?") +
      geom_segment(aes(x=1870, y=490, xend=1905, yend=240), size=1, arrow=arrow(length=unit(0.5, "cm")))
  }

  if(ye>1955){
    h <- h + annotate("text", x =1960, y = 400, label="Beginning of civil rights movement") +
      geom_segment(aes(x=1950, y = 450, xend=1955, yend = 640), size=1, arrow=arrow(length=unit(0.5, "cm")))
  }

  if(ye>1960){
    h <- h + annotate("text", x= 1866, y=515, label="Another") +
      geom_segment(aes(x=1882, y=500, xend=1955, yend=680), size=1, arrow=arrow(length=unit(0.5, "cm")))
  }

  i <- plot_grid(g,h,align='h')
  print(i)
}
singleyear(2017)
## Warning: Removed 1 rows containing missing values (geom_point).

OK. It looks like hell. But! In just a moment, it will look. Well, not exactly perfect, but at least much better.

The way to animate is this: Define a function that gives you the frames you want, as a function of an iterable. That’s already done. Call this:

saveGIF({
  for (ye in 1860:2017){
   singleyear(ye)
  }
}
, interval=0.3, ani.width=1280, ani.height=720)

Enjoy. Oh, and note, that it will crash if you try to animate it a notebook.

Hvor blev jeg af?

Tja. Godt spørgsmål. Der har været meget stille her i et stykke tid.

Det har der været før. Det bliver der sikkert igen. Denne gang har det nok været som reaktion på ændringer på min arbejdsplads. Der jo nok, hvis vi virkelig skal kigge dybt i sjælen, udløste noget der kunne ligne en depression. Ikke noget alvorligt. Afgjort ikke nok til at udløse piller. Men bare en længere periode med – “Fuck. Var det det?” tanker. Og ikke specielt systematiske overvejelser om hvad katten jeg så skulle bruge tiden på.

Det er jeg så nogenlunde ude af. Der begynder at være fod på tingene på hjemmefronten. Arbejdet er, nåja, arbejde. Det virker ikke så håbløst som det har gjort. Og jeg er nok ved at vænne mig til, at identitet er noget der skal findes andre steder end på jobbet. Ligesom anerkendelse og respekt.

Så med lidt held kommer der til at ske lidt mere her. Der er nørdeprojekter undervejs, faktisk godt i gang. Der er køkkenteknikker der skal afprøves. Der er politiske kæpheste der skal luftes. Og så er det fredag, og lige om lidt skal jeg i biografen og se præsentationen af noget et af de projekter jeg har gang i har kastet af sig.