title: “numbers and ggplot2” output: html_document

Let’s try some fibonacci numbers:

##  [1]      1      1      2      3      5      8     13     21     34     55
## [11]     89    144    233    377    610    987   1597   2584   4181   6765
## [21]  10946  17711  28657  46368  75025 121393 196418 317811 514229 832040

Note: default in qplot makes a bar graph, and plot makes scatterplot if we pass only one argument. Best two pass both x axis vector and y axis vector in all cases. I like the looks of qplot, so I’ll stick with it.

qplot(Term, FibNum)

Let’s try some prime analysis:

Here are the first 95 primes:

##  [1]   2   3   5   7  11  13  17  19  23  29  31  37  41  43  47  53  59
## [18]  61  67  71  73  79  83  89  97 101 103 107 109 113 127 131 137 139
## [35] 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233
## [52] 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337
## [69] 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439
## [86] 443 449 457 461 463 467 479 487 491 499

Here are the next 95 primes:

##  [1]  503  509  521  523  541  547  557  563  569  571  577  587  593  599
## [15]  601  607  613  617  619  631  641  643  647  653  659  661  673  677
## [29]  683  691  701  709  719  727  733  739  743  751  757  761  769  773
## [43]  787  797  809  811  821  823  827  829  839  853  857  859  863  877
## [57]  881  883  887  907  911  919  929  937  941  947  953  967  971  977
## [71]  983  991  997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063
## [85] 1069 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151

And the next 95 primes

##  [1] 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237
## [15] 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327
## [29] 1361 1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453
## [43] 1459 1471 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553
## [57] 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637
## [71] 1657 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753
## [85] 1759 1777 1783 1787 1789 1801 1811 1823 1831 1847 1861

*Now the 95 primes between 10000 and 10889

##  [1] 10007 10009 10037 10039 10061 10067 10069 10079 10091 10093 10099
## [12] 10103 10111 10133 10139 10141 10151 10159 10163 10169 10177 10181
## [23] 10193 10211 10223 10243 10247 10253 10259 10267 10271 10273 10289
## [34] 10301 10303 10313 10321 10331 10333 10337 10343 10357 10369 10391
## [45] 10399 10427 10429 10433 10453 10457 10459 10463 10477 10487 10499
## [56] 10501 10513 10529 10531 10559 10567 10589 10597 10601 10607 10613
## [67] 10627 10631 10639 10651 10657 10663 10667 10687 10691 10709 10711
## [78] 10723 10729 10733 10739 10753 10771 10781 10789 10799 10831 10837
## [89] 10847 10853 10859 10861 10867 10883 10889

Notice that as primes get larger, there are more gaps, and the primes tend to come in clumps.

Comparing the slopes of the four graphs: The domains are a constant 95; the ranges are 500, 650, 712, 889 respectively. So slopes are 500/95=2.6, 650/95=6.8, 715/95=7.5, 889/95=9.4. This increasing slope indicates that, on avarage, primes get farther apart as they get larger, as we would expect.

Here are more examples of how clumping occurs with larger primes:

These are the 77 primes between 200,000 and 201,000

##  [1] 200003 200009 200017 200023 200029 200033 200041 200063 200087 200117
## [11] 200131 200153 200159 200171 200177 200183 200191 200201 200227 200231
## [21] 200237 200257 200273 200293 200297 200323 200329 200341 200351 200357
## [31] 200363 200371 200381 200383 200401 200407 200437 200443 200461 200467
## [41] 200483 200513 200569 200573 200579 200587 200591 200597 200609 200639
## [51] 200657 200671 200689 200699 200713 200723 200731 200771 200779 200789
## [61] 200797 200807 200843 200861 200867 200869 200881 200891 200899 200903
## [71] 200909 200927 200929 200971 200983 200987 200989

## [1] 77

And these are the 85 primes between 300,000 and 301,000:

##  [1] 300007 300017 300023 300043 300073 300089 300109 300119 300137 300149
## [11] 300151 300163 300187 300191 300193 300221 300229 300233 300239 300247
## [21] 300277 300299 300301 300317 300319 300323 300331 300343 300347 300367
## [31] 300397 300413 300427 300431 300439 300463 300481 300491 300493 300497
## [41] 300499 300511 300557 300569 300581 300583 300589 300593 300623 300631
## [51] 300647 300649 300661 300667 300673 300683 300691 300719 300721 300733
## [61] 300739 300743 300749 300757 300761 300779 300787 300799 300809 300821
## [71] 300823 300851 300857 300869 300877 300889 300893 300929 300931 300953
## [81] 300961 300967 300973 300977 300997

## [1] 85

Notice that there are more primes between 300,000 and 301,000 than between 200,000 and 201,000. Is this what we expected?

Should make density plots of primes with several intervals on same plot. (intervals vs density of primes). Say: 10000, 20000, 30000, …

Here they are: integers 1-80000, in 80 groups, plotted against number of primes in each group of 1000 integers.

## Total Number of Primes =  10101

There is lots more exploration to be done!