Skip to content

Instantly share code, notes, and snippets.

@bertbalcaen
Last active December 29, 2015 15:59
Show Gist options
  • Save bertbalcaen/7694911 to your computer and use it in GitHub Desktop.
Save bertbalcaen/7694911 to your computer and use it in GitHub Desktop.
Example of a scatterplot created with Processing. You'll need to create a 'data' folder inside the sketch folder and save twitter.csv inside it. Data: Top 100 Twitter users according to number of followers (in 2010?). Based on https://docs.google.com/spreadsheet/ccc?key=0AonYZs4MzlZbdFRwUEJxd1pQYTF0N0VqSENoY1Z6dWc#gid=0.
Username Description Followers Following No of tweets Label
@nytimes News Organisation 3028263 433 60693 ja
@BreakingNews News Organisation 2302858 353 48774 ja
@mashable Media Organisation 2230623 2230 33229 ja
@PerezHilton Blogger 3093601 296 32357 ja
@eonline Media Organisation 2770717 31347 30949 ja
@SouljaBoy Musician 2685282 459 26111 ja
@TIME News Organisation 2413050 165 21033 ja
@ivetesangalo Musician 2205250 234 17753 ja
@MCHammer Musician 2060587 37076 16562 ja
@NBA Sports organistion 2386490 835 15872
@KhloeKardashian TV Personality 2699940 104 15525
@iamdiddy Musician 3469483 1189 11922
@InStyle Magazine / website 1929374 2077 11890
@DwightHoward Athlete 1914071 4758 10475
@cnnbrk News Organisation 4058556 39 8642
@RevRunWisdom Musician 1944863 0 8428
@justinbieber Musician 8268465 110480 8420 ja
@UberSoc Twitter Ap 2798544 1931 8260
@stephenfry Actor / Writer 2364724 52784 8099
@serenawilliams Athlete 1970494 105 7998
@TheOnion Media Organisation 2685659 6 7568
@NICKIMINAJ Musician 2857113 620 7535
@KimKardashian Television personality 6831755 123 6971 ja
@ParisHilton Model / Socialite 3635292 1688 6934
@petewentz Musician 2219970 222 6782
@lancearmstrong Athlete 2771654 212 6732
@aplusk Actor 6468885 620 6548 ja
@DENISE_RICHARDS Actress 1952913 140 5990
@peoplemag Media Organisation 2436927 602 5918
@SnoopDogg Musician 2912946 1337 5273 ja
@rainnwilson Actor / Comedian 2240689 198 4623
@ddlovato Actress / Singer 2738608 111 4618
@RyanSeacrest Radio/ TV host 4171005 365 4491
@mrskutcher Actress 3427066 205 4456
@huckluciano TV host 2850953 251 4411
@tonyhawk Athlete 2342551 270 4394
@nfl Sports organistion 1994183 135 4269
@NickCannon Actor / Comedian 2332008 457 4178
@funnyordie Comedy video site 1941139 2938 4153
@TheEllenShow Comedian 6211423 48816 4055
@juanes Musician 2065803 534 4018
@noaheverett Twitpic founder 2143906 1071 3764
@THE_REAL_SHAQ Athlete 3636450 626 3571
@jimmyfallon Actor / Comedian 3322005 3270 3469
@50cent Musician 4266221 2 3413
@GiulianaRancic TV Host 2099324 309 3407
@YouTube Video website 2107974 234 3385
@106andpark Music Video show 2113425 216 3205
@johnlegend Musician 2250780 189 2676
@katyperry Musician 6321858 70 2673 ja
@lilyroseallen Musician 2734258 130 2652
@Pink Musician 3495423 106 2454
@MarthaStewart Bussiness woman 2158823 8216 2351
@chelseahandler Comedian 3231838 45 2302
@JimCarrey Actor 2775662 1 2280
@google News Organisation 2889198 354 2278
@whitehouse Politics 2013570 118 2277
@drdrew TV personality 2130519 262 2257
@ricky_martin Musician 2571717 144 2249
@KourtneyKardash TV Personality 2309836 43 1975
@KAKA Athlete 3143726 290 1906
@rustyrockets Comedian 2044563 58 1831
@ashleytisdale Actress 4086656 105 1532
@NellyFurtado Musician 1950223 237 1513
@selenagomez Actress / Singer 4446711 468 1465
@tyrabanks Model / TV host 2810106 597 1445
@StephenAtHome Political satirist / Comedian 2120681 0 1417
@kanyewest Musician 2797738 0 1402
@rihanna Musician 4059894 310 1394
@nickjonas Musician 2345549 131 1383
@joelmchale Comedian / TV host 2076083 126 1337
@Schwarzenegger Actor / Politician 1975786 109900 1326
@BarackObama Politician 7079610 701159 1294 ja
@aliciakeys Musician 3345029 162 1229 ja
@alyankovic Musician / Comedian 1974642 195 1153
@JonasBrothers Musician 2668543 1246 1133
@chrisbrown Musician 2007808 564 1076
@twitter Social Network 4646765 431 1041
@shakira Musician 4928764 38 924
@taylorswift13 Musician 5688178 54 879
@coldplay Musician 3562189 2467 795
@SaraBareilles Musician 1993152 64 783
@TheMandyMoore Musician 2239374 36 696
@JessicaSimpson Actress / Singer 3569544 79 692
@britneyspears Musician 7177928 416576 646 ja
@ladygaga Musician 8914965 144223 642 ja
@LennyKravitz Musician 2193138 1889 560
@Cristiano Footballer 2122622 52 517
@jtimberlake Musician 4177146 20 470
@TwitPic Social Network 3250584 28169 463
@ConanOBrien TV host / Comedian 2701611 1 412
@twitter_es Social Network 4291736 20 389
@drakkardnoir Musician 2009458 254 378
@algore Former politician & businessman 2223561 9 309
@BillGates Microsoft Chairman 2344149 63 266
@Oprah TV host/ Actress 5391885 22 180
@ashsimpsonwentz Musician 2409351 84 174
@shitmydadsays Author/ blogger 2126361 1 138
@charliesheen Actor 3024234 35 125
@Eminem Musician 3539765 0 117
// Exporteren naar PDF is geen standaard functionaliteit - je hebt daar een externe library voor nodig.
// Hier laten we Processing weten dat we die PDF library willen gebruiken.
import processing.pdf.*;
// Basis instellingen.
size(1000, 600);
background(255);
// De CSV moet in de sketch folder staan, in een map met de naam 'data'.
// Data van CSV inladen in de variabele 'rijen'.
// De variabele 'rijen' is een array, een lijst dus.
// Elke element uit de lijst 'rijen' stemt overeen met 1 rij uit de CSV.
// vb: Lady Gaga (@ladygaga),Musician,8914965,144223,642
String rijen[] = loadStrings("twitter.csv");
// Alles wat nu komt zal ook in de PDF zichtbaar zijn.
// De PDF zal in de map van onze sketch staan, met als naam 'twitter.pdf'.
beginRecord(PDF, "twitter.pdf");
// We geven elk element uit onze lijst dezelfde behandeling.
for(int teller = 0; teller < rijen.length; teller ++){
// Als we de eerste rij inlezen is onze teller gelijk aan nul.
// Deze rij willen we overslaan, want die bevat de headings: Username, Description, Followers, Following, No of tweets, Label
if(teller == 0){
continue;
}
// We nemen de rij met als nummer 'teller', en stoppen die in de variabele 'rij'.
String rij = rijen[teller];
// De variabele 'rij' bevat nu een lang stuk tekst, terwijl wij met de individuele kolommen willen werken.
// We moeten dus de tekst in kolommen verdelen, en dat doen we door die te 'spiltten' op de komma.
String kolommen[] = split(rij, ',');
// We maken hier aparte variabelen voor de verschillende kolommen.
// Het datatype van de variabelen kolommen is een array van Strings.
// Dat is ook voor tekstuele gegevens, maar als de cijfers willen we niet als tekst gaan behandelen, maar als getal.
// Dus moeten we die omzetten naar integers met int().
String naam = kolommen[0]; // 1e kolom
int followers = int(kolommen[2]); // 3e kolom
int following = int(kolommen[3]); // 4e kolom
int tweets = int(kolommen[4]); // 5é kolom
String label = kolommen[5]; // 6e kolom
float x = map(followers, 1914071, 8914965, 0, width);
float y = map(tweets, 0, 60693, height, 0);
float r = map(following, 0, 701159, 5, 20);
stroke(0);
noFill();
ellipse(x, y, r, r);
if(label.equals("ja")){
noStroke();
fill(255, 0, 0);
text(naam, x, y);
}
}
// We zijn klaar met onze PDF, en dat moeten we laten weten aan Processing.
endRecord();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment