library(plyr)
library(reshape2)
library(ggplot2)
popwide <- read.table(header=TRUE, con <- textConnection('
Year "North America" "Latin America" Europe Africa CIS "Middle East" Asia Oceania World
-10000 39 278 548 242 159 176 738 251 2431
-9000 52 363 759 343 238 241 1317 252 3564
-8000 70 489 1062 490 357 336 2079 253 5136
-7000 93 680 1499 708 536 476 3316 255 7562
-6000 125 967 2134 1032 804 811 5332 257 11461
-5000 167 1405 3067 1517 1207 1668 8629 260 17920
-4000 223 2093 4447 2352 1810 2896 14284 265 28370
-3000 300 3164 6558 4148 2715 4246 23417 273 44820
-2000 402 4851 10291 6260 4072 7034 38914 284 72108
-1000 540 7580 16727 9264 6108 10146 64400 302 115066
0 725 11982 29331 15186 9162 14805 106722 327 188239
100 762 12695 30979 16627 8622 15922 109126 331 195062
200 800 13451 32617 18270 8146 17097 111595 334 202310
300 841 14253 31165 19315 7729 17288 114387 338 205317
400 884 15105 29718 20677 7366 17555 117263 342 208910
500 929 16011 25858 22307 6881 17862 120236 346 210430
600 977 16973 21859 24446 6440 18273 123325 351 212643
700 1027 17998 23913 28185 6209 19164 128983 356 225835
800 1080 19090 26150 32915 6015 20059 134817 362 240488
900 1203 21703 29197 37126 6353 21195 151598 372 268747
1000 1325 24329 32260 41465 6692 20204 168382 383 295040
1100 1440 27235 38060 44319 8940 18175 214043 395 352607
1200 1602 30163 50553 47743 12131 19271 231209 408 393081
1300 1742 33127 69479 53532 12812 18618 202672 421 392404
1400 1931 36137 50947 57880 12815 16607 213026 432 389775
1500 2100 39220 68423 62207 15947 17726 255241 505 461368
1600 984 8808 86304 72815 19495 21594 343376 579 553956
1700 1227 12259 98182 80209 23015 21253 366370 651 603168
1710 1695 12869 104329 81334 24897 21596 387455 650 634825
1720 2173 13503 108686 81583 26990 21900 400832 660 656327
1730 2658 14164 113145 81891 29128 22210 406257 671 670123
1740 3151 14857 117711 82256 31313 22526 482732 683 755229
1750 3654 15586 122394 82677 33549 22848 532260 695 813664
1760 4168 16360 127197 83153 35838 23178 549044 710 839647
1770 4697 17185 132037 83681 38186 23514 561886 725 861912
1780 5244 18086 137451 84263 40594 23857 640791 742 951028
1790 5811 19058 143375 84900 43068 24209 666761 761 987944
1800 7331 20116 149018 85589 45613 24568 656800 783 989818
1810 9369 21695 156044 86829 48232 24975 712646 785 1060575
1820 12014 23750 167212 89180 51414 25400 719855 824 1089649
1830 15526 27206 181736 93552 54904 26448 758867 898 1159136
1840 20033 30531 196591 98188 62259 27472 776126 1029 1212230
1850 26214 34345 208429 102932 66759 28522 794119 1361 1262682
1860 35307 38471 222202 107457 75190 29597 778869 2075 1289168
1870 42871 42262 236910 114301 81713 30782 779866 2742 1331447
1880 55128 47062 257452 122176 93277 33091 808041 3368 1419596
1890 68232 56723 277683 131306 106298 35358 858880 4444 1538923
1900 81731 66092 300365 140755 120822 37195 902207 5265 1654431
1910 98849 79000 327620 150281 146446 39033 929800 6146 1777175
1920 114875 95631 334449 164856 142757 42287 1009871 7384 1912111
1930 133685 117370 361068 181280 152706 45912 1091191 8680 2091894
1940 143860 132146 380248 200895 180943 53497 1205957 9805 2307348
1950 171555 167747 398657 222945 177167 59788 1335745 11273 2544877
1960 204072 220425 431871 280842 208207 78320 1604981 14076 3042795
1970 231833 287342 466558 360787 235918 103736 2006299 17364 3709837
1980 255439 364160 491112 471082 258009 141099 2459870 19939 4460710
1990 283805 443788 506846 631002 281307 193533 2944422 22895 5307597
2000 315552 523211 518664 818847 281719 241784 3419032 26024 6144834
'))
close(con)
worldpop <- data.frame(Year = popwide$Year, Population = popwide$World)
save(worldpop, file = "../data/worldpop.rda")
if (F) {
poplong <- melt(popwide, id.vars="Year", measure.vars=2:9, variable.name="Region", value.name="Population")
# Find world population from sums
poptotal <- ddply(poplong, "Year", summarise, Population=sum(Population))
# Is it the same as the HYDE total? Close. Probably some rounding errors.
poptotal$Population - popwide$World
png('test-%d.png', width=400, height=300)
ggplot(poptotal, aes(x=Year, y=Population)) + geom_line() + geom_point()
#ggplot(poptotal, aes(x=Year, y=Population)) + geom_line() + geom_point() + scale_y_log10()
ggplot(poplong, aes(x=Year, y=Population)) +
geom_area(aes(fill=Region), colour="black")
#ggplot(poplong, aes(x=Year, y=Population)) +
# geom_area(aes(fill=Region), colour="black") +
# scale_y_log10()
dev.off()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.