├── .gitignore ├── GoogleGeocodeMap.R ├── GoogleSuggest.R ├── README ├── bmi.R ├── data ├── fdic.csv ├── ohlo_2010-08-16.txt └── stackoverflow.txt ├── fdic.R ├── git_lang_stats.txt ├── github_followers.R ├── github_lang_stats.R ├── google-ai-2010 ├── googleAI2010.csv └── googleAI2010.rb ├── heart_rate_max.R ├── heart_rate_max.csv ├── mandelbrot.R ├── mars ├── 20151105_mars_lander_map_f840.jpg ├── Mars_MGS_colorhillshade_mola_1024.jpg ├── Mars_Viking_MDIM21_ClrMosaic_global_1024.jpg ├── mariner-9-mars.jpg ├── mars.R ├── mars.Rproj ├── mars.csv ├── states.sqlite ├── test.db └── the_martian.csv ├── middle_earth_map.R ├── moon ├── moon.R ├── moon.Rproj ├── moon.csv └── moon.png └── radar_charts.R /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | -------------------------------------------------------------------------------- /GoogleGeocodeMap.R: -------------------------------------------------------------------------------- 1 | getDocNodeVal=function(doc, path) 2 | { 3 | sapply(getNodeSet(doc, path), function(el) xmlValue(el)) 4 | } 5 | 6 | gGeoCode=function(str) 7 | { 8 | library(XML) 9 | u=paste('http://maps.google.com/maps/api/geocode/xml?sensor=false&address=',str) 10 | doc = xmlTreeParse(u, useInternal=TRUE) 11 | str=gsub(' ','%20',str) 12 | lng=getDocNodeVal(doc, "/GeocodeResponse/result/geometry/location/lat") 13 | lat=getDocNodeVal(doc, "/GeocodeResponse/result/geometry/location/lng") 14 | c(lat,lng) 15 | } 16 | 17 | bullseyeEtc=function(str) 18 | { 19 | for (i in 1:10){points(loc[1],loc[2],col=heat.colors(10)[i],cex=i)} 20 | for (i in 1:10){points(loc[1],loc[2],col=heat.colors(10)[i],cex=i*.5)} 21 | title(main='The R User Conference 2010', sub='July 20-23, 2010') 22 | mtext("NIST: Gaithersburg, Maryland, USA") 23 | mtext("http://user2010.org",4) 24 | } 25 | 26 | loc=gGeoCode('100 Bureau Drive Gaithersburg, MD, 20899, USA') 27 | 28 | # World 29 | map('world', plot=TRUE, fill=TRUE);bullseyeEtc() 30 | 31 | # USA 32 | map('usa', plot=TRUE, fill=TRUE);bullseyeEtc() 33 | 34 | # State 35 | map('state','Maryland', plot=TRUE, fill=TRUE);bullseyeEtc() -------------------------------------------------------------------------------- /GoogleSuggest.R: -------------------------------------------------------------------------------- 1 | googleSuggest = function(str='') 2 | { 3 | library(XML) 4 | str=gsub(' ','%20',str) # URL - escape spaces 5 | u=paste('http://google.com/complete/search?output=toolbar&q=',str, sep='') 6 | doc = xmlTreeParse(u, useInternal=TRUE) 7 | 8 | search_string=sapply(getNodeSet(doc, "//CompleteSuggestion/suggestion"), function(el){xmlGetAttr(el,"data")}) 9 | count=sapply(getNodeSet(doc, "//CompleteSuggestion/num_queries"), function(el){xmlGetAttr(el,"int")}) 10 | df=as.data.frame(cbind(search_string,count)) 11 | 12 | # My numbers behave strangely. So I do this conversion... Why??? 13 | df$count=as.numeric(as.character(df$count)) 14 | df 15 | } 16 | 17 | # This function iterating through to get each letter of the alphabet... 18 | # for example 19 | # http://google.com/complete/search?output=toolbar&q=how%20can%20i%a 20 | # http://google.com/complete/search?output=toolbar&q=how%20can%20i%b 21 | # ... 22 | # 23 | # I especially like the concise syntax for iterating through the letters of the alphabet 24 | # http://stackoverflow.com/questions/1439513/creating-a-sequential-list-of-letters-with-r 25 | # 26 | 27 | googleSuggestAll = function(str='') 28 | { 29 | queries = paste(str,letters) 30 | df=data.frame() 31 | for (i in 1:length(queries)) { 32 | df=rbind(df,googleSuggest(queries[i]) ) 33 | } 34 | df=df[with(df, order(df$count, decreasing=TRUE)),] 35 | df 36 | } -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | The home for various R Programs. Visit http://www.r-chart.com for more information. -------------------------------------------------------------------------------- /bmi.R: -------------------------------------------------------------------------------- 1 | # 2 | # Optimal Weight: Derived from BMI Calculation 3 | # 4 | optimal_weight = function (height, bmi){round((height**2 * bmi) / 703)} 5 | 6 | # 7 | # Create an R data frame which is matrix similar to 8 | # http://www.nhlbi.nih.gov/guidelines/obesity/bmi_tbl.htm 9 | # 10 | create_bmi_dataframe =function (bmi_start=19, bmi_end=54,height_inches_start=60, height_inches_end=80) 11 | { 12 | bmi=c(bmi_start:bmi_end) 13 | 14 | height=(c(height_inches_start:height_inches_end)) 15 | df=data.frame(matrix(NA, ncol=length(bmi), nrow=length(height))) 16 | 17 | for (i in height){ 18 | for (j in bmi){ 19 | df[i-height_inches_start+1,j-bmi_start+1]=optimal_weight(i,j) 20 | } 21 | } 22 | 23 | rownames(df)=height 24 | colnames(df)=bmi 25 | df 26 | } 27 | 28 | # Examples 29 | # create_bmi_dataframe() 30 | print(create_bmi_dataframe(bmi_end=30)) 31 | 32 | # 33 | # http://www.cdc.gov/healthyweight/assessing/bmi/adult_bmi/index.html 34 | # BMI 35 | # Weight Status 36 | # Below 18.5 Underweight 37 | # 18.5 to 24.9 Normal 38 | # 25.0 to 29.9 Overweight 39 | # 30.0 and Above Obese 40 | # 41 | # http://en.wikipedia.org/wiki/Body_mass_index 42 | # 30 Obese Class 1 43 | # 35 Obese Class 2 44 | # 40 Obese Class 3 45 | # 46 | 47 | bmi=c(18.5,25,30,35,40) 48 | height=(c(60:80)) 49 | df=data.frame(matrix(NA, ncol=length(bmi), nrow=length(height))) 50 | 51 | for (i in height){ 52 | j_index=0 53 | for (j in bmi){ 54 | j_index = j_index + 1 55 | df[i-60+1,j_index]=optimal_weight(i,j) 56 | } 57 | } 58 | 59 | rownames(df)=height 60 | colnames(df)=c('Underweight','Normal', 'Overweight','Obese Class 1', 'Obese Class 2') 61 | 62 | df$height=rownames(df) 63 | df2=melt(df, id='height') 64 | 65 | ggplot(data=df2, aes(x=height, y=value, group=variable, color=variable)) + 66 | geom_line() + 67 | scale_colour_discrete(name='BMI Upper Limit') + 68 | scale_x_discrete('Height in Inches') + 69 | scale_y_continuous('Weight in Pounds') 70 | 71 | ggsave('BMI.png') 72 | dev.off() -------------------------------------------------------------------------------- /data/fdic.csv: -------------------------------------------------------------------------------- 1 | , Statistics At A Glance,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2 | Historical Trends,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 3 | ,,,,,,,,,,,,,,,," As of March 31, 2010",,,,,,,,,,,,,,,,,,,,,,,,, 4 | ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 5 | Dollar Amounts in Billions,,2010 YTD,2009,,2008,,2007,2006,,2005,,2004,,2003,,2002,,2001,,2000,,1999,,1998,,1997,,1996,,1995,,1994,,1993,,1992,,1991,,1990, 6 | ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 7 | Commercial Banks,,"6,772","6,839",,"7,086",,"7,283","7,401",,"7,526",,"7,631",,7770,,"7,888",,"8,080",,"8,315 ",,"8,580 ",,"8,774 ",,"9,143 ",,"9,528 ",,"9,941 ",,"10,452 ",,"10,959 ",,"11,463 ",,"11,921 ",,"12,343 ", 8 | New Charters,,2,25,,89,,164,178,,166,,122,,110,,91,,126,,190 ,,230 ,,188 ,,187 ,,145 ,,102 ,,50 ,,58 ,,72 ,,105 ,,163 , 9 | Mergers,,33,152,,261,,282,305,,269,,261,,224,,276,,354,,452 ,,416 ,,557 ,,598 ,,552 ,,606 ,,548 ,,501 ,,425 ,,443 ,,389 , 10 | ,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,, 11 | Savings Institutions,,"1,160","1,173",,"1,219",,"1,251","1,279",,"1,307",,"1,345",,"1,411",,"1,466",,"1,534",,"1,589 ",,"1,642 ",,"1,690 ",,"1,780 ",,"1,926 ",,"2,030 ",,"2,152 ",,"2,262 ",,"2,390 ",,"2,561 ",,"2,815 ", 12 | New Charters,,1,6,,9,,17,16,,13,,6,,8,,4,,20,,33 ,,40 ,,33 ,,12 ,,12 ,,9 ,,18 ,,9 ,,8 ,,9 ,,28 , 13 | Mergers,,4,27,,32,,39,37,,41,,58,,49,,56,,63,,81 ,,80 ,,114 ,,127 ,,108 ,,116 ,,109 ,,111 ,,84 ,,72 ,,64 , 14 | ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 15 | Problem Institutions,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,, 16 | Number,,775,702,,252,,76,50,,52,,80,,116,,136,,114,,94,,79,,84,,92,,117 ,,193 ,,318 ,,575 ,,"1,066 ",,"1,430 ",,"1,496 ", 17 | Assets,$,431,403,,159,,22,8,,7,,28,,30,,39,,40,,24,,10,,11,,6,,12 ,,31 ,,73 ,,348 ,,601 ,,837 ,,647 , 18 | ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 19 | Combined Dep. Ins. Fund,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 20 | Fund Balance,$,-20.7,-20.9,,17.3,,52.4,50.2,,48.6,,47.5,,46.0,,43.8,,41.4,,41.7,,39.7,,39.4,,37.7,,35.7,,28.8,,23.8,,14.3,,0.2,,-6.9,,4.1, 21 | Insured Deposits,$,"5,463","5,392",,"4,749",,"4,292","4,154",,"3,891",,"3,622",,"3,452",,"3,384",,"3,211",,"3,055",,"2,869",,"2,850",,"2,746",,"2,691",,"2,664",,"2,589",,"2,602",,"2,675",,"2,734",,"2,760", 22 | Reserve Ratio,%,-0.38,-0.39,,0.36,,1.22,1.21,,1.25,,1.31,,1.33,,1.29,,1.29,,1.36,,1.38,,1.38,,1.37,,1.33,,1.08,,0.92,,0.55,,0.01,,-0.25,,0.15, 23 | ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 24 | Number Failed Institutions,,41,140,,25,,3,0,,0,,4,,3,,11,,4,,7,,8,,3,,1,,6,,8,,15,,50,,179,,268,,381, 25 | Failed Assets*,$,22.140,169.709,,371.945,,2.615,0.000,,0.000,,0.170,,0.947,,3.383,,1.821,,0.414,,1.592,,0.290,,0.028,,0.233,,1.226,,1.601,,9.977,,89.554,,143.455,,146.586, 26 | ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 27 | Number Assisted Institutions,,0,8,,5,,0,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,0,,2,,3,,1, 28 | Assisted Assets*,$,0.000,"1,917.482",,"1,306.042",,0.000,0.000,,0.000,,0.000,,0.000,,0.000,,0.000,,0.000,,0.000,,0.000,,0.000,,0.000,,0.000,,0.000,,0.000,,0.034,,0.079,,0.014, 29 | ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 30 | Estimated Losses(DIF),$,6.305,35.615,,17.982,,0.120,0.000,,0.000,,0.004,,0.066,,0.376,,0.271,,0.032,,0.616,,0.226,,0.005,,0.061,,0.113,,0.194,,0.698,,7.447,,15.120,,22.030, 31 | Resolution Receivables**,$,39.091,37.288,,15.766,,0.808,0.482,,0.533,,0.722,,0.784,,0.793,,1.429,,0.354,,0.805,,0.757,,1.114,,4.45,,4.143,,8.197,,13.396,,27.824,,18.675,,12.935, 32 | ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 33 | Number of FDIC Employees***,,"6,822","6,558",,"4,988",,"4,532","4,476",,"4,514",,"5,078",,"5,311",,"5,430",,"6,167",,"6,452 ",,"7,266 ",,"7,359 ",,"7,793 ",,"9,151 ",,"11,856 ",,"17,526 ",,"20,994 ",,"22,459 ",,"22,586 ",,"19,247 ", 34 | (Includes RTC before 1996),,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 35 | * Prior years have been revised to reflect failed/assisted assets as reported on the Call Report for the quarter prior to failure/assistance.,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 36 | ** Includes remaining receivership assets from prior years,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 37 | "*** Beginning in 2008, FDIC began reporting the number of FDIC employees based on a new, full-time eqivalent methodology.",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 38 | Prior years have been revised to reflect the number of employees as reported in the FDIC Annual Report.,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 39 | ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 40 | ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 41 | 42 | 43 | 44 | 45 | ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 46 | -------------------------------------------------------------------------------- /data/ohlo_2010-08-16.txt: -------------------------------------------------------------------------------- 1 | Name;URL;Contributors;Code;Total Lines;Projects;Blanks;Comments;Commits 2 | Limbo;/languages/75;60;2249944;2539527;75;190240;99343;1128 3 | Clojure;/languages/80;131;38440;47067;38;6574;2053;2518 4 | Eiffel;/languages/60;388;6275446;8178716;164;1140433;762837;77011 5 | modula3;/languages/82;2;80;116;3;20;16;3 6 | Boo;/languages/26;208;180998;258290;158;39262;38030;4128 7 | Haskell;/languages/38;1772;2950024;4055602;920;537382;568196;82524 8 | Automake;/languages/50;20994;5559385;7847350;9667;1283839;1004126;678804 9 | Classic Basic;/languages/59;105;51416;55692;89;2565;1711;486 10 | Fortran (Fixed-format);/languages/40;1212;25986573;30032721;597;1542809;2503339;34395 11 | Tcl;/languages/25;2731;13324110;19263602;1241;2518818;3420674;116785 12 | Structured Basic;/languages/58;543;3884019;4720700;396;579698;256983;10864 13 | shell script;/languages/11;57153;141029568;180286345;34721;17637607;21619170;1044886 14 | Objective-C;/languages/16;6555;20878929;29977577;3842;4822999;4275649;261154 15 | Java;/languages/5;78098;921373701;1564831542;44068;208686754;434771087;6334194 16 | CUDA;/languages/84;64;74197;116525;43;20987;21341;880 17 | Pike;/languages/43;563;1760616;2986325;50;408569;817140;86531 18 | DOS batch script;/languages/13;24423;-109173300;-108407199;18234;385997;380104;149014 19 | BlitzMax;/languages/68;41;300105;630684;35;136315;194264;2417 20 | XML;/languages/3;133183;1360685233;1444684454;88167;47455920;36543301;4117303 21 | VHDL;/languages/57;270;2649655;3288871;170;291278;347938;2781 22 | Lisp;/languages/22;1140;8308471;10776479;672;1312363;1155645;91593 23 | HTML;/languages/1;106012;831577441;975180721;68481;101287167;42316113;3569340 24 | Nix;/languages/71;45;66543;91149;21;19413;5193;9857 25 | OpenGL Shading;/languages/69;998;357852;622292;718;134032;130408;6694 26 | C++;/languages/44;61831;956435749;1447753638;27448;218314478;273003411;5595074 27 | ChaiScript;/languages/85;2;727;879;2;137;15;74 28 | ClearSilver;/languages/31;205;50561;56511;57;4684;1266;2648 29 | CSS;/languages/4;72060;104313061;129520527;51086;16046935;9160531;882220 30 | Erlang;/languages/28;714;6684204;9434162;439;1123445;1626513;37688 31 | C/C++;/languages/7;4627;45110875;64641470;229;8731582;10799013;148240 32 | XAML;/languages/67;1687;2544566;2788575;1599;157275;86734;24085 33 | Rexx;/languages/24;95;113423;174488;68;29507;31558;526 34 | R;/languages/65;1428;2868196;3362805;980;260133;234476;37604 35 | DCL;/languages/45;1666;852157;1230404;938;72611;305636;8228 36 | Puppet;/languages/86;50;7100;9015;18;1401;514;408 37 | HaXe;/languages/66;240;837005;1244381;169;147454;259922;8323 38 | Pascal;/languages/14;3071;64245769;85187716;2067;10024647;10917300;164984 39 | Objective-J;/languages/70;217;293754;381581;109;47248;40579;2567 40 | XML Schema;/languages/35;11950;51079641;55370999;7867;1793333;2498025;90993 41 | TeX/LaTeX;/languages/37;10686;23986757;32704296;5957;5408866;3308673;201184 42 | Smalltalk;/languages/39;292;810903;1191242;186;222274;158065;2572 43 | CMake;/languages/74;5291;1810558;2730336;2337;420800;498978;137452 44 | IDL/PV-WAVE/GDL;/languages/76;1861;1015411;1541165;1118;185528;340226;21406 45 | Dylan;/languages/33;62;1471540;1921899;9;256780;193579;6937 46 | C#;/languages/17;22198;194694928;284170420;14299;34366660;55108832;956581 47 | Visual Basic;/languages/15;3734;15473149;21248160;2877;2744004;3031007;56705 48 | Emacs Lisp;/languages/10;2979;14635015;19290459;1473;1930940;2724504;200550 49 | Assembly;/languages/19;7971;82516559;103340891;3948;8683062;12141270;153177 50 | Factor;/languages/62;86;269438;349445;9;64409;15598;15188 51 | Lua;/languages/27;3590;28200080;34074335;2066;3163410;2710845;132239 52 | Vala;/languages/34;318;529182;745611;169;110299;106130;20813 53 | AWK;/languages/18;2686;1496647;1762707;1681;96929;169131;12520 54 | MetaFont;/languages/46;19783;1821164;2040560;15464;161330;58066;189360 55 | Perl;/languages/8;27308;93627570;160461291;14710;30483368;36350353;1199537 56 | MetaPost;/languages/47;193;7720222;8629750;127;892384;17144;10293 57 | C;/languages/42;78023;1726253783;2472505438;32814;324600740;421650915;7947485 58 | PHP;/languages/2;36952;561850169;917082496;20230;104197015;251035312;2751427 59 | XSL Transformation;/languages/36;12749;45653917;55721747;8265;5873101;4194729;156628 60 | Vim Script;/languages/48;1155;4424458;5584056;757;382907;776691;15323 61 | Scala;/languages/55;656;1190431;1906692;374;282555;433706;34848 62 | All Languages;/languages;208;180998;258290;158;39262;38030;4128 63 | Fortran (Free-format);/languages/41;762;1795475;2316088;440;200563;320050;8245 64 | D;/languages/32;2445;15241254;18559662;1524;1228836;2089572;40686 65 | Brainfuck++;/languages/79;1;1109;1433;2;92;232;16 66 | ActionScript;/languages/53;5605;25547230;44769557;4195;6337495;12884832;142192 67 | Autoconf;/languages/51;24239;190696304;215757919;11531;24337944;723671;648814 68 | MXML;/languages/54;2557;1165861;1525579;1964;186353;173365;39436 69 | Make;/languages/52;50328;48204642;65448041;28434;9043943;8199456;1301644 70 | Haml;/languages/64;746;120921;145298;449;18798;5579;11801 71 | Stratego;/languages/63;247;1194499;1723993;159;297968;231526;6395 72 | Scilab;/languages/73;185;581312;813765;86;70987;161466;9127 73 | oberon;/languages/83;1;64;96;2;16;16;2 74 | Groovy;/languages/29;1960;2503099;3728441;1247;514808;710534;52828 75 | JavaScript;/languages/6;60677;532961714;758288096;40329;95138575;130187807;1353159 76 | Exheres;/languages/56;97;78407;115447;14;23516;13524;16210 77 | Brainfuck;/languages/78;13;859;937;14;47;31;58 78 | SQL;/languages/30;28069;91652481;103881444;17963;5853258;6375705;335916 79 | octave;/languages/72;491;143134;343060;272;53600;146326;4767 80 | F#;/languages/77;198;42553;65536;155;12441;10542;3061 81 | Matlab;/languages/23;1924;9832467;15478101;1260;2269323;3376311;41848 82 | Scheme;/languages/20;2205;9345709;11903089;1173;1294664;1262716;92038 83 | Ruby;/languages/12;12651;69492150;98543867;7083;13431655;15620062;528791 84 | Python;/languages/9;38691;147956908;230148427;21811;35477930;46713589;2446946 85 | Ebuild;/languages/49;1755;1638248;2334584;460;431628;264708;380538 86 | Ada;/languages/21;681;17290761;30206064;454;5431622;7483681;38454 87 | Objective Caml;/languages/61;1061;6095253;8809635;503;1105032;1609350;93889 88 | Modula-2;/languages/81;1111;1032305;1254997;628;134332;88360;5966 89 | -------------------------------------------------------------------------------- /fdic.R: -------------------------------------------------------------------------------- 1 | # http://www.fdic.gov/bank/statistical/stats/2010mar/fdic.xls 2 | # File --> Save As .csv 3 | 4 | df=read.csv('data/fdic.csv',header=TRUE, skip=4) 5 | head(df) 6 | 7 | # Remove Empty Columns 8 | df=df[c(-2,-5,-7,-10,-12,-14,-16,-18,-20,-22,-24,-26,-28,-30,-32,-34,-36,-38,-40,-42)] 9 | 10 | # Remove Rows with Trailing information 11 | df=df[-(29:36),] 12 | 13 | # fix the column names 14 | colnames(df)=gsub('X','',colnames(df)) 15 | colnames(df)=gsub('X','',colnames(df)) 16 | colnames(df)[1]='Statistic' 17 | colnames(df)[2]='2010' # But remember this is YTD 18 | 19 | # I am kind of fuzzy about the rules - but it seems like you just have to try casting columns as factors in one 20 | # context and as characters in another to get the desired result. If there is a set rule about usage, please let 21 | # me know. At this point, I am accepting that these types are not handled in a consistent way and you just have 22 | # to know how a particular function behaves. 23 | # 24 | df$Statistic=as.character(df$Statistic) 25 | 26 | # Trim leading white space 27 | df$Statistic=gsub('^ *','',df$Statistic) 28 | 29 | # Remove Subheadings - include them inline 30 | # Could do this by explicit naming 31 | df$Statistic[11]='Problem Institutions Number' 32 | df$Statistic[12]='Problem Institutions Assets' 33 | 34 | # This is a bit more generic 35 | df$Statistic[3]=paste(df$Statistic[2],df$Statistic[3]) 36 | df$Statistic[4]=paste(df$Statistic[2],df$Statistic[4]) 37 | df$Statistic[7]=paste(df$Statistic[6],df$Statistic[7]) 38 | df$Statistic[8]=paste(df$Statistic[6],df$Statistic[8]) 39 | df$Statistic[15]=paste(df$Statistic[14],df$Statistic[15]) 40 | df$Statistic[16]=paste(df$Statistic[14],df$Statistic[16]) 41 | df$Statistic[17]=paste(df$Statistic[14],df$Statistic[17]) 42 | 43 | # Remove Rows with no data (Empty Rows and Subheading Rows) 44 | df=df[c(-1,-5,-9,-10,-13,-14,-18,-21,-24, -27),] 45 | 46 | # At this point, we have the actual statistical data isolated. 47 | # However, it would easier use the data if it were pivotted. 48 | 49 | # You can quickly pivot by transposing it - but the result is a matrix full of string data 50 | t(df) 51 | 52 | # Better to use the reshape package 53 | library(reshape) 54 | df.melted=melt(df, id="Statistic") 55 | 56 | # Strip out all commas and cast the values to numerics. Keep in mind, there are $ amounts and % for different stats 57 | df.melted$value=as.numeric(gsub(',','',as.character(df.melted$value))) 58 | colnames(df.melted)[2]='Year' 59 | df.melted$Year=as.numeric(as.character(df.melted$Year)) 60 | 61 | # Pretty much done with the data set as a whole. Now create subsets: 62 | fdic_employees= df.melted[df$Statistic=='Number of FDIC Employees***',c('Year','value')] 63 | fdic_employees$Year=factor(fdic_employees$Year) 64 | fdic_employees$value=factor(fdic_employees$value) 65 | colnames(fdic_employees)=c('Year','Number') 66 | 67 | # Can break up into individual series 68 | df$Statistic 69 | pin=df.melted[df.melted$Statistic=="Problem Institutions Number",] 70 | cb= df.melted[df.melted$Statistic=="Commercial Banks",] 71 | si=df.melted[df.melted$Statistic=="Savings Institutions",] 72 | 73 | # Another way to manipulate data frames is using sqldf 74 | # The following compares several of the series with eachother. 75 | library('sqldf') 76 | 77 | pct_prob=sqldf('SELECT 78 | p.Year Year, 79 | p.value prob, c.value + s.value "Total Institutions", 80 | p.value / (c.value + s.value) * 100 "Percent Problem" 81 | FROM pin p 82 | JOIN cb c ON c.Year = p.Year 83 | JOIN si s ON s.Year = p.Year') 84 | 85 | library(ggplot2) 86 | p = qplot(data=pct_prob, Year, `Percent Problem`, color=`Total Institutions`, group=1) 87 | p = p + geom_line() 88 | p + opts(axis.text.x=theme_text(angle=-90, hjust=0), title='Total FDIC Problem Institutions by Year') 89 | ggsave('totalFDICProblemInstitutionsByYear.png') 90 | 91 | fdicPlot=function(statistic){ 92 | 93 | f=df.melted[df.melted$Statistic==statistic,] 94 | ggplot(data=f, aes(x=Year, y=value)) + geom_line() + geom_point() + opts(title=statistic) 95 | img=paste(gsub(" |\\(|\\)|\\*",'',i),'.png',sep='') 96 | ggsave(img) 97 | 98 | } 99 | 100 | for (i in df$Statistic){fdicPlot(i)} 101 | dev.off() -------------------------------------------------------------------------------- /git_lang_stats.txt: -------------------------------------------------------------------------------- 1 | Language;Repositories;Users;Source Code 2 | ActionScript;2609;1104;0 3 | Arc;48;15;0 4 | ASP;88;35;0 5 | Assembly;41;5;0 6 | Boo;41;6;0 7 | C;16137;5558;0 8 | C#;6061;2706;0 9 | C++;12521;5595;0 10 | Clojure;2082;481;0 11 | CoffeeScript;34;2;0 12 | ColdFusion;180;56;0 13 | Common Lisp;0;0;0 14 | D;197;64;0 15 | Delphi;43;16;0 16 | Duby;4;0;0 17 | Eiffel;39;15;0 18 | Emacs Lisp;0;0;0 19 | Erlang;2520;532;0 20 | F#;74;5;0 21 | FORTRAN;93;47;0 22 | Go;398;103;0 23 | Groovy;870;261;0 24 | Haskell;2290;641;0 25 | HaXe;75;14;0 26 | Io;57;3;0 27 | Java;17687;6618;0 28 | JavaScript;44482;10895;0 29 | Lua;1754;511;0 30 | Max/MSP;4;2;0 31 | Nu;40;4;0 32 | Objective-C;8027;2520;0 33 | Objective-J;355;109;0 34 | OCaml;382;121;0 35 | ooc;112;11;9396 36 | Perl;34232;2178;0 37 | PHP;21685;8872;0 38 | Pure Data;0;0;0 39 | Python;32150;8775;0 40 | R;191;69;0 41 | Racket;20;8;0 42 | Ruby;104239;23123;0 43 | Scala;2154;539;0 44 | Scheme;707;140;0 45 | sclang;2;0;0 46 | Self;7;3;0 47 | Shell;4657;1011;0 48 | Smalltalk;80;14;0 49 | SuperCollider;53;11;0 50 | Tcl;125;39;0 51 | Vala;27;3;0 52 | Verilog;74;26;0 53 | VHDL;64;14;0 54 | VimL;4248;1267;0 55 | Visual Basic;0;0;0 56 | -------------------------------------------------------------------------------- /github_followers.R: -------------------------------------------------------------------------------- 1 | library(rjson) 2 | library(RCurl) 3 | library(igraph) 4 | 5 | githubFollowers = function (userToPlot) 6 | { 7 | user_relations=NULL 8 | u <- paste('https://api.github.com/users/', userToPlot, '/followers', sep='') 9 | o <- fromJSON(getURL(u)) 10 | df <- as.data.frame(t(sapply(o, unlist))) 11 | df$user <- userToPlot 12 | 13 | if(nrow(df) > 1){ 14 | user_relations <- data.frame(from=df$login, to=df$user) 15 | } 16 | print(paste(userToPlot,' ',nrow(user_relations))) 17 | user_relations 18 | } 19 | 20 | githubGraph = function (userToPlot) 21 | { 22 | relations <- githubFollowers(userToPlot) 23 | 24 | for (i in 1:nrow(relations)) { 25 | follower <- as.character(relations[i,]$from) 26 | follower_relations <- githubFollowers(follower) 27 | 28 | if(!is.null(follower_relations)){ 29 | relations <- merge(relations, follower_relations, all=T) 30 | } 31 | } 32 | 33 | relations 34 | } 35 | 36 | userToPlot='EzGraphs' 37 | relations = githubGraph(userToPlot) 38 | g <- graph.data.frame(relations, directed = T) 39 | V(g)$label <- V(g)$name 40 | plot(g) 41 | tkplot(g) 42 | rglplot(g) 43 | 44 | -------------------------------------------------------------------------------- /github_lang_stats.R: -------------------------------------------------------------------------------- 1 | library(ggplot2) 2 | library(sqldf) 3 | 4 | # Read the Data 5 | df=read.csv('git_lang_stats.txt',header=TRUE,';') 6 | 7 | # Data munging to prep for plotting 8 | df=sqldf("SELECT Language, Repositories, Users from df order by Repositories Desc") 9 | df.top_ten_reps = sqldf("SELECT * from df where rowid <= 10 order by Repositories Desc") 10 | df.top_ten_reps$Language = factor(df.top_ten_reps$Language) # Why do we need to factor - or names "bleed through" 11 | df.top_ten_users = sqldf("SELECT * from df where rowid <= 10 order by Users Desc") 12 | df.top_ten_users$Language = factor(df.top_ten_users$Language) # Why do we need to factor - or names "bleed through" 13 | 14 | # Bar Charts 15 | ggplot(data=df.top_ten_reps, aes(Language,Repositories)) + geom_bar() + coord_flip() + opts(title='Top 10 Languages by Github Repositories') 16 | ggsave('top_10_github_languages_by_reps.png') 17 | 18 | ggplot(data=df.top_ten_users, aes(Language,Users)) + geom_bar() + coord_flip() + opts(title='Top 10 Languages by Github Users') 19 | ggsave('top_10_github_languages_by_users.png') 20 | 21 | # Scatter plots with Line 22 | x=coef(lm(Repositories ~ Users, data=df.top_ten_users)) 23 | ggplot(data=df.top_ten_reps, aes(Users,Repositories, color=Language)) + geom_point() + stat_abline(intercept= x[1], slope=x[2], color='brown') +opts(title=paste('Repositories per User:',x[2])) 24 | ggsave('github_languages_reps_per_user_top10.png') 25 | 26 | # Scatter plots with Line 27 | x=coef(lm(Repositories ~ Users, data=df)) 28 | ggplot(data=df, aes(Users,Repositories)) + geom_point() + stat_abline(intercept= x[1], slope=x[2], color='brown') +opts(title=paste('Repositories per User:',x[2])) 29 | ggsave('github_languages_reps_per_user_all.png') 30 | 31 | dev.off() 32 | 33 | total.reps=sum(df$Repositories) 34 | df$Rep.pct=round((df$Repositories/total.reps) * 100,2 ) 35 | 36 | df$Ratio=df$Repositories / df$Users 37 | mean(df[df$Ratio > 0 & df$User > 0 & !is.na(df$Ratio), ]) 38 | 39 | df 40 | -------------------------------------------------------------------------------- /google-ai-2010/googleAI2010.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ezgraphs/R-Programs/ed2f3c769f248a0c7ec93103b0dbc65643b76c7c/google-ai-2010/googleAI2010.csv -------------------------------------------------------------------------------- /google-ai-2010/googleAI2010.rb: -------------------------------------------------------------------------------- 1 | # http://ai-contest.com/rankings.php?page=1 2 | # Country list 3 | # Language list 4 | # Organization list 5 | # Take the top n of each Language, sum (ranking and or score) to provide metric about the languages representation in the competition 6 | # Could map or geocode 7 | require 'rubygems' 8 | require 'hpricot' 9 | require 'open-uri' 10 | 11 | 1.upto(47){|i| 12 | 13 | doc=Hpricot(open("http://ai-contest.com/rankings.php?page=#{i}")) 14 | t=doc/'table[@class="leaderboard"]' 15 | 16 | (t/'tbody/tr').each{|r| 17 | ranking = (r/'/td[1]/').text 18 | username = (r/'/td[2]/a/').text 19 | country=((r/'/td[3]/a/img').first[:title]) 20 | organization = (r/'/td[4]/a/').text 21 | language = (r/'/td[5]/a/').text 22 | score=(r/'/td[6]/').text 23 | 24 | str="#{ranking};#{username};#{country};#{organization};#{language};#{score};" 25 | puts str 26 | 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /heart_rate_max.R: -------------------------------------------------------------------------------- 1 | library(ggplot2) 2 | 3 | df <- read.csv('heart_rate_max.csv', sep=';') 4 | df2 <- melt(df, id="Age") 5 | 6 | ggplot(data=df2, aes(x=Age, y=value, group=variable, color=variable)) + geom_line() + opts(title='Comparison of HR Max Calculation Methods')+scale_colour_discrete(name='Calculation') + scale_y_continuous('Beats per Minute') 7 | ggsave('max_heart_rate_calculation_methods.png') 8 | 9 | ggplot(data=df2, aes(x=Age, y=value)) + opts(title='Max Heart Rate (Smoothed)') + geom_smooth(aes(group=1)) 10 | ggsave('all_methods_smoothed.png') 11 | 12 | ggplot(data=df2, aes(x=Age, y=value, group=variable, color=variable)) + geom_point() + opts(title='Max Heart Rate (Smoothed)') + geom_smooth(aes(group=1)) 13 | ggsave('all_methods_smoothed_points.png') 14 | 15 | women <- df2[grep('women$', df2$variable),] 16 | ggplot(data=women, aes(x=Age, y=value, group=variable, color=factor(variable))) + geom_line() + opts(title='Women')+scale_colour_discrete(name='Calculation') +scale_y_continuous('Beats per Minute') 17 | ggsave('women_heart_rate_max.png') 18 | 19 | 20 | # matrix <- t(df) 21 | # colnames(matrix) <- matrix[1,] 22 | # matrix <- matrix[-1,] 23 | # df3=as.data.frame(matrix) 24 | # df4=as.data.frame(mean(df3)) 25 | # men <- df2[grep('_men', df2$variable),] 26 | # both_men_and_women <- c(grep('women$', df2$variable),grep('_men', df2$variable)) 27 | # both <- df2[-both_men_and_women,] 28 | 29 | # df4$Age <- rownames(df4) 30 | # df4$variable <- 'Mean' 31 | # colnames(df4) <- c('value','Age', 'variable') 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /heart_rate_max.csv: -------------------------------------------------------------------------------- 1 | Age;Traditional;Least_objectionable;Londeree_and_Moeschberger;Miller_et_al_from_Indiana_University;Tanaka_method;Lund_and_Sweden_-_men;Oakland_University_2007_nonlinear;Martha_Gulati_et_al_-_women;Lund_and_Sweden_-women 2 | 18;202;193.47;193.502;201.7;195.4;192.539283018565;189.232;190.16;186.956904952213 3 | 19;201;192.785;192.791;200.85;194.7;192.186000360237;188.973;189.28;186.809293603672 4 | 20;200;192.1;192.08;200.0;194.0;191.822224722414;188.7;188.4;186.655091031514 5 | 21;199;191.415;191.369;199.15;193.3;191.447688602094;188.413;187.52;186.494014756349 6 | 22;198;190.73;190.658;198.3;192.6;191.062120502149;188.112;186.64;186.325771290632 7 | 23;197;190.045;189.947;197.45;191.9;190.665245064276;187.797;185.76;186.15005581256 8 | 24;196;189.36;189.236;196.6;191.2;190.256783218195;187.468;184.88;185.966551840468 9 | 25;195;188.675;188.525;195.75;190.5;189.836452347911;187.125;184.0;185.774930908943 10 | 26;194;187.99;187.814;194.9;189.8;189.403966475869;186.768;183.12;185.574852248063 11 | 27;193;187.305;187.103;194.05;189.1;188.959036465837;186.397;182.24;185.365962467309 12 | 28;192;186.62;186.392;193.2;188.4;188.501370245358;186.012;181.36;185.147895245824 13 | 29;191;185.935;185.681;192.35;187.7;188.030673048595;185.613;180.48;184.920271030932 14 | 30;190;185.25;184.97;191.5;187.0;187.546647680407;185.2;179.6;184.682696746945 15 | 31;189;184.565;184.259;190.65;186.3;187.048994802461;184.773;178.72;184.434765516532 16 | 32;188;183.88;183.548;189.8;185.6;186.537413242184;184.332;177.84;184.176056397098 17 | 33;187;183.195;182.837;188.95;184.9;186.011600325329;183.877;176.96;183.906134134855 18 | 34;186;182.51;182.126;188.1;184.2;185.471252232905;183.408;176.08;183.624548939495 19 | 35;185;181.825;181.415;187.25;183.5;184.916064383176;182.925;175.2;183.330836282597 20 | 36;184;181.14;180.704;186.4;182.8;184.345731839406;182.428;174.32;183.024516723171 21 | 37;183;180.455;179.993;185.55;182.1;183.759949743963;181.917;173.44;182.705095763986 22 | 38;182;179.77;179.282;184.7;181.4;183.158413779352;181.392;172.56;182.372063742594 23 | 39;181;179.085;178.571;183.85;180.7;182.540820656658;180.853;171.68;182.024895761254 24 | 40;180;178.4;177.86;183.0;180.0;181.906868631829;180.3;170.8;181.663051660211 25 | 41;179;177.715;177.149;182.15;179.3;181.256258050131;179.733;169.92;181.285976039085 26 | 42;178;177.03;176.438;181.3;178.6;180.588691919017;179.152;169.04;180.893098331418 27 | 43;177;176.345;175.727;180.45;177.9;179.903876509531;178.557;168.16;180.483832937683 28 | 44;176;175.66;175.016;179.6;177.2;179.201521986286;177.948;167.28;180.05757942237 29 | 45;175;174.975;174.305;178.75;176.5;178.481343065903;177.325;166.4;179.613722781 30 | 46;174;174.29;173.594;177.9;175.8;177.743059703654;176.688;165.52;179.151633783215 31 | 47;173;173.605;172.883;177.05;175.1;176.986397807948;176.037;164.64;178.670669398307 32 | 48;172;172.92;172.172;176.2;174.4;176.21108998208;175.372;163.76;178.170173309785 33 | 49;171;172.235;171.461;175.35;173.7;175.416876292551;174.693;162.88;177.649476525766 34 | 50;170;171.55;170.75;174.5;173.0;174.603505063045;174.0;162.0;177.107898092143 35 | 51;169;170.865;170.039;173.65;172.3;173.770733692989;173.293;161.12;176.544745915599 36 | 52;168;170.18;169.328;172.8;171.6;172.91832949939;172.572;160.24;175.959317703618 37 | 53;167;169.495;168.617;171.95;170.9;172.046070580477;171.837;159.36;175.350902028646 38 | 54;166;168.81;167.906;171.1;170.2;171.153746699415;171.088;158.48;174.71877952351 39 | 55;165;168.125;167.195;170.25;169.5;170.241160186158;170.325;157.6;174.062224215095 40 | 56;164;167.44;166.484;169.4;168.8;169.308126855272;169.548;156.72;173.380505003055 41 | 57;163;166.755;165.773;168.55;168.1;168.35447693732;168.757;155.84;172.672887290028 42 | 58;162;166.07;165.062;167.7;167.4;167.380056021158;167.952;154.96;171.938634769443 43 | 59;161;165.385;164.351;166.85;166.7;166.384726004246;167.133;154.08;171.177011376468 44 | 60;160;164.7;163.64;166.0;166.0;165.368366047849;166.3;153.2;170.387283406988 45 | 61;159;164.015;162.929;165.15;165.3;164.330873533743;165.453;152.32;169.568721808761 46 | 62;158;163.33;162.218;164.3;164.6;163.272165018807;164.592;151.44;168.720604647919 47 | 63;157;162.645;161.507;163.45;163.9;162.19217718366;163.717;150.56;167.842219752948 48 | 64;156;161.96;160.796;162.6;163.2;161.090867771261;162.828;149.68;166.932867536983 49 | 65;155;161.275;160.085;161.75;162.5;159.968216511189;161.925;148.8;165.991863997898 50 | 66;154;160.59;159.374;160.9;161.8;158.824226025124;161.008;147.92;165.018543894033 51 | 67;153;159.905;158.663;160.05;161.1;157.65892270884;160.077;147.04;164.012264091657 52 | 68;152;159.22;157.952;159.2;160.4;156.472357585896;159.132;146.16;162.972407078338 53 | 69;151;158.535;157.241;158.35;159.7;155.264607128048;158.173;145.28;161.898384634267 54 | 70;150;157.85;156.53;157.5;159.0;154.035774037275;157.2;144.4;160.7896416513 55 | 71;149;157.165;155.819;156.65;158.3;152.785987984265;156.213;143.52;159.645660087083 56 | 72;148;156.48;155.108;155.8;157.6;151.515406298105;155.212;142.64;158.465963039029 57 | 73;147;155.795;154.397;154.95;156.9;150.224214601936;154.197;141.76;157.250118920246 58 | 74;146;155.11;153.686;154.1;156.2;148.912627389314;153.168;140.88;155.997745716742 59 | 75;145;154.425;152.975;153.25;155.5;147.580888536103;152.125;140.0;154.708515302387 60 | 76;144;153.74;152.264;152.4;154.8;146.22927174278;151.068;139.12;153.382157785253 61 | 77;143;153.055;151.553;151.55;154.1;144.858080902223;149.997;138.24;152.018465856106 62 | 78;142;152.37;150.842;150.7;153.4;143.46765038818;148.912;137.36;150.617299107052 63 | 79;141;151.685;150.131;149.85;152.7;142.058345259869;147.813;136.48;149.178588285654 64 | 80;140;151.0;149.42;149.0;152.0;140.630561378449;146.7;135.6;147.702339447359 65 | 81;139;150.315;148.709;148.15;151.3;139.184725431372;145.573;134.72;146.188637966804 66 | 82;138;149.63;147.998;147.3;150.6;137.721294861053;144.432;133.84;144.637652366626 67 | 83;137;148.945;147.287;146.45;149.9;136.240757694643;143.277;132.96;143.049637920757 68 | 84;136;148.26;146.576;145.6;149.2;134.743632272198;142.108;132.08;141.424939988061 69 | 85;135;147.575;145.865;144.75;148.5;133.230466870992;140.925;131.2;139.763997031448 70 | 86;134;146.89;145.154;143.9;147.8;131.701839224275;139.728;130.32;138.067343277471 71 | 87;133;146.205;144.443;143.05;147.1;130.158355933347;138.517;129.44;136.33561097191 72 | 88;132;145.52;143.732;142.2;146.4;128.600651772405;137.292;128.56;134.569532187952 73 | 89;131;144.835;143.021;141.35;145.7;127.029388886273;136.053;127.68;132.76994014542 74 | 90;130;144.15;142.31;140.5;145.0;125.445255881744;134.8;126.8;130.937770002047 75 | -------------------------------------------------------------------------------- /mandelbrot.R: -------------------------------------------------------------------------------- 1 | library(ggplot2) 2 | 3 | max_iter=25 4 | cl=colours() 5 | step=seq(-2,0.8,by=0.005) 6 | points=array(0,dim=c(length(step)^2,3)) 7 | t=0 8 | 9 | for(a in step) 10 | { 11 | for(b in step+0.6) 12 | { 13 | x=0;y=0;n=0;dist=0 14 | while(n% 9 | rownames_to_column( var = "car" ) %>% # tibble 10 | mutate_each(funs(rescale), -car) %>% # scales 11 | melt(id.vars=c('car'), measure.vars=colnames(mtcars)) %>% 12 | arrange(car) 13 | 14 | # Line Plot 15 | df %>% 16 | filter(variable=='mpg') %>% 17 | ggplot(aes(x=car, y=value, group=1)) + 18 | geom_line(color = 'purple') 19 | 20 | # Line Plot with polar coordinates 21 | df %>% 22 | filter(variable=='mpg') %>% 23 | ggplot(aes(x=car, y=value, group=1)) + 24 | geom_line(color = 'purple') + 25 | coord_polar() 26 | 27 | # Switch to geom_polygon to avoid gap. 28 | df %>% 29 | filter(variable=='mpg') %>% 30 | ggplot(aes(x=car, y=value, group=1)) + 31 | geom_polygon(color = 'purple', fill=NA) 32 | 33 | # Polar chart version 1 34 | df %>% 35 | filter(variable=='mpg') %>% 36 | ggplot(aes(x=car, y=value, group=1)) + 37 | geom_polygon(color = 'purple', fill=NA) + 38 | coord_polar() + theme_bw() 39 | 40 | # Facet by variable 41 | df %>% 42 | ggplot(aes(x=car, y=value, group=variable, color=variable)) + 43 | geom_polygon(fill=NA) + 44 | coord_polar() + theme_bw() + facet_wrap(~ variable) + 45 | #scale_x_discrete(labels = abbreviate) + # Can increase the text size and uncomment 46 | theme(axis.text.x = element_text(size = 3)) 47 | 48 | # Facet by car 49 | df %>% 50 | ggplot(aes(x=variable, y=value, group=car, color=car)) + 51 | geom_polygon(fill=NA) + 52 | coord_polar() + theme_bw() + facet_wrap(~ car) 53 | --------------------------------------------------------------------------------