├── Bar_Charts_Basics ├── bar-chart-making.R └── data │ ├── ACS_08_3YR_S1903 │ ├── ACS_08_3YR_S1903.csv │ ├── ACS_08_3YR_S1903.txt │ ├── ACS_08_3YR_S1903_ann.csv │ ├── ACS_08_3YR_S1903_metadata.csv │ └── aff_download_readme.txt │ ├── income-2008-13.csv │ ├── income-totals.csv │ └── state_geocodes_v2011.csv ├── Bubbles_Chart ├── bubbles.R ├── crimeRatesByState2008.csv └── final-bubbles.pdf ├── Chernoff_faces ├── Crime Chernoff Faces by state-edited.pdf ├── chernoff.R └── data │ ├── .Rhistory │ ├── crimeRatesByState-formatted.csv │ ├── crimeRatesByState-formatted.xls │ └── statab2008_0301_CrimeRatesByState2004And2005AndByTy.xls ├── Connected_Scatterplots ├── .Rhistory ├── connected_scatter.R └── jamie-counts.csv ├── Distributions_Plots └── distributions.R ├── Dot_Plots ├── data │ ├── ACS_13_1YR_S2002 │ │ ├── ACS_13_1YR_S2002.csv │ │ ├── ACS_13_1YR_S2002.txt │ │ ├── ACS_13_1YR_S2002_ann.csv │ │ ├── ACS_13_1YR_S2002_metadata.csv │ │ └── aff_download_readme.txt │ ├── ACS_13_1YR_S2401-by-occ.csv │ ├── ACS_13_1YR_S2401-by-occ.xlsx │ ├── ACS_13_1YR_S2401 │ │ ├── ACS_13_1YR_S2401.csv │ │ ├── ACS_13_1YR_S2401.txt │ │ ├── ACS_13_1YR_S2401_ann.csv │ │ ├── ACS_13_1YR_S2401_metadata.csv │ │ └── aff_download_readme.txt │ └── ACS_13_5YR_B20002 │ │ ├── ACS_13_5YR_B20002.csv │ │ ├── ACS_13_5YR_B20002.txt │ │ ├── ACS_13_5YR_B20002_metadata.csv │ │ └── aff_download_readme.txt └── scatterplot-making.R ├── Draw_in_R_+_Custom_Plots └── drawing-tutorial.R ├── Heatmap ├── nba_heatmap.R ├── nba_heatmap_revised.pdf └── ppg2008.csv ├── Heatmap_2 ├── .Rhistory ├── 2008-09nba.trunc.csv └── heatmaps-custom.R ├── Interactive_Choropleth_Map └── interactivemap │ ├── Blank_US_Map.svg │ ├── blankmap.js │ ├── index.html │ ├── jquery-1.4.4.min.js │ ├── raphael-min.js │ ├── reset.css │ ├── unemp.css │ ├── unemp.json │ └── zoomandpan.js ├── Line_Charts ├── data │ ├── country-regions.csv │ └── life-expectancy-cleaned.csv └── line-making.R ├── Moving_Past_Default_R_Charts ├── data │ ├── country-regions.csv │ └── life-expectancy-cleaned.csv └── style-with-base.R ├── Slopegraph ├── pct-gdp.txt └── slopegraph.R ├── Small_Multiples ├── areagraph.R ├── data │ ├── 12s0121-truncated.txt │ ├── 12s0121-truncated.xls │ └── 12s0121.xls └── multiples.R └── Text_display ├── areagraph.R ├── labels-tutorial.R └── unisexCnts.RData /Bar_Charts_Basics/bar-chart-making.R: -------------------------------------------------------------------------------- 1 | ##### 2 | # 3 | # How to Make a Bar Chart 4 | # 5 | ##### 6 | 7 | 8 | # 9 | # Load data 10 | # 11 | 12 | income <- read.csv("data/income-totals.csv", stringsAsFactors=FALSE, sep=",", colClasses=c("FIPS"="character")) 13 | 14 | 15 | # 16 | # Default bar chart 17 | # 18 | 19 | barplot(income$med_income) 20 | 21 | 22 | # 23 | # Axes 24 | # 25 | 26 | # Labels 27 | barplot(income$med_income, names.arg=income$name) 28 | 29 | par(mar=c(8,4,2,2)) 30 | barplot(income$med_income, names=income$name, las=2, mgp=c(3,0.3,0)) 31 | 32 | # Rotate 33 | par(mar=c(5, 6, 2, 2)) 34 | barplot(income$med_income, names.arg=income$name, las=2, horiz=TRUE, cex.names=0.6, cex.axis=0.8) 35 | 36 | 37 | 38 | 39 | # 40 | # Sorting 41 | # 42 | 43 | # By value 44 | income_desc <- income[order(income$med_income, decreasing=FALSE),] 45 | par(mar=c(5, 6, 2, 2)) 46 | barplot(income_desc$med_income, names.arg=income_desc$name, las=2, 47 | horiz=TRUE, cex.names=0.6, cex.axis=0.8) 48 | 49 | # By name 50 | income_desc <- income[order(income$name, decreasing=TRUE),] 51 | par(mar=c(5, 6, 2, 2)) 52 | barplot(income_desc$med_income, names.arg=income_desc$name, 53 | las=2, horiz=TRUE, cex.names=0.6, cex.axis=0.8) 54 | 55 | 56 | # 57 | # Grouping 58 | # 59 | 60 | # Merge with state names 61 | income0813 <- read.csv("data/income-2008-13.csv", stringsAsFactors=FALSE, 62 | sep=",", colClasses=c("FIPS"="character")) 63 | income0813 <- merge(income[,c("FIPS", "name")], income0813, by="FIPS") 64 | 65 | 66 | # Grouped bar chart 67 | barplot(as.matrix(income0813[1:3, c("med2008", "med2013")]), beside=TRUE, 68 | legend.text=income0813$name[1:3]) 69 | 70 | par(mar=c(8,4,2,2)) 71 | rotate <- function(x) t(apply(x, 2, rev)) 72 | income_rotated <- rotate(as.matrix(income0813[, c("med2008", "med2013")])) 73 | barplot(income_rotated[,1:10], beside=TRUE, legend.text=c("2008", "2013"), names.arg=c(income0813$name[1:10]), cex.axis=0.7, cex.names=0.7, las=2) 74 | 75 | 76 | # Indexed categories 77 | regions <- read.csv("data/state_geocodes_v2011.csv", stringsAsFactors=FALSE, colClasses=c("Region"="character", "Division"="character", "FIPS"="character", "Name"="character")) 78 | income_more <- merge(income, regions, by="FIPS") 79 | unique_regions <- unique(income_more$Region) 80 | 81 | bar_names <- c() 82 | bar_heights <- c() 83 | for (i in 1:length(unique_regions)) { 84 | 85 | curr_region <- subset(regions, Region==unique_regions[i] & FIPS=="00" & Division == "0") 86 | bar_names <- c(bar_names, NA, toupper(curr_region$Name)) 87 | bar_heights <- c(bar_heights, NA, NA) 88 | 89 | states <- subset(income_more, Region == unique_regions[i]) 90 | states <- states[order(states$med_income, decreasing=TRUE),] 91 | bar_names <- c(bar_names, states$Name) 92 | bar_heights <- c(bar_heights, states$med_income) 93 | } 94 | 95 | par(mar=c(5, 8, 2, 2)) 96 | barplot(rev(bar_heights), names.arg=rev(bar_names), las=2, horiz=TRUE, cex.names=0.7, cex.axis=0.7) 97 | 98 | 99 | 100 | # Separate charts 101 | par(mfrow=c(2,2), mar=c(5, 8, 4, 2)) 102 | for (i in 1:length(unique_regions)) { 103 | curr_region <- subset(regions, Region==unique_regions[i] & FIPS=="00" & Division == "0") 104 | 105 | states <- subset(income_more, Region == unique_regions[i]) 106 | states <- states[order(states$med_income, decreasing=TRUE),] 107 | barplot(states$med_income, names.arg=states$Name, las=2, horiz=TRUE, cex.names=0.7, cex.axis=0.7, xlim=c(0, 75000), main=curr_region$Name) 108 | } 109 | 110 | 111 | # 112 | # Change the look 113 | # 114 | 115 | par(mar=c(5, 6, 4, 2)) 116 | 117 | # Space and border 118 | barplot(states$med_income, names.arg=states$Name, las=2, horiz=TRUE, cex.names=0.7, cex.axis=0.7, xlim=c(0, 75000), main=curr_region$Name, border=NA, space=0.4) 119 | 120 | 121 | # Color 122 | barplot(states$med_income, names.arg=states$Name, las=2, horiz=TRUE, cex.names=0.8, cex.axis=0.7, xlim=c(0, 75000), main=curr_region$Name, border=NA, space=0.2, col="darkred") 123 | 124 | barplot(states$med_income, names.arg=states$Name, las=2, horiz=TRUE, cex.names=0.8, cex.axis=0.7, xlim=c(0, 75000), main=curr_region$Name, border=NA, space=0.2, col=c(rep("gray", length(states$Name)-1), "darkred")) 125 | 126 | 127 | # Random space and color 128 | par(mfrow=c(3,3)) 129 | for (i in 1:9) { 130 | 131 | random_space <- runif(1, 0.01, 1.9) 132 | random_colors <- sample(colors(), length(states$Name)) 133 | barplot(states$med_income, names.arg=states$Name, las=2, horiz=TRUE, cex.names=0.8, cex.axis=0.7, xlim=c(0, 75000), main=curr_region$Name, border=NA, space=random_space, col=random_colors) 134 | } 135 | 136 | 137 | # Grid lines 138 | par(mar=c(5, 8, 5, 2)) 139 | barplot(rev(bar_heights), names.arg=rev(bar_names), las=1, horiz=TRUE, cex.names=0.7, cex.axis=0.7, border=NA, space=0.3, main="Median Household Income, 2013") 140 | grid(NULL, NA, col="white", lty="solid", lwd=0.7) 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /Bar_Charts_Basics/data/ACS_08_3YR_S1903/ACS_08_3YR_S1903.txt: -------------------------------------------------------------------------------- 1 | S1903 2 | Median Income in the Past 12 Months (In 2008 Inflation-Adjusted Dollars) 3 | 4 | For information on confidentiality protection, sampling error, 5 | nonsampling error, and definitions, see Survey Methodology. 6 | 7 | 8 | 9 | Source: U.S. Census Bureau, 2006-2008 American Community Survey 10 | 11 | 12 | Data are based on a sample and are subject to sampling variability. The degree of uncertainty 13 | for an estimate arising from sampling variability is represented through the use of a margin of 14 | error. The value shown here is the 90 percent margin of error. The margin of error can be 15 | interpreted roughly as providing a 90 percent probability that the interval defined by the 16 | estimate minus the margin of error and the estimate plus the margin of error (the lower and 17 | upper confidence bounds) contains the true value. In addition to sampling variability, 18 | the ACS estimates are subject to nonsampling error (for a discussion of nonsampling variability, see 19 | Accuracy of the Data). 20 | The effect of nonsampling error is not represented in these tables. 21 | 22 | 23 | Notes: 24 | 25 | 26 | 27 | While the 2008 American Community Survey (ACS) data 28 | generally reflect the November 2007 Office of Management and Budget 29 | (OMB) definitions of metropolitan and micropolitan statistical 30 | areas; in certain instances the names, codes, and boundaries of the 31 | principal cities shown in ACS tables may differ from the OMB 32 | definitions due to differences in the effective dates of the 33 | geographic entities. The 2008 Puerto Rico Community Survey (PRCS) 34 | data generally reflect the November 2007 Office of Management and 35 | Budget (OMB) definitions of metropolitan and micropolitan 36 | statistical areas; in certain instances the names, codes, and 37 | boundaries of the principal cities shown in PRCS tables may differ 38 | from the OMB definitions due to differences in the effective dates 39 | of the geographic entities. 40 | 41 | 42 | Estimates of urban and rural population, housing units, 43 | and characteristics reflect boundaries of urban areas defined based 44 | on Census 2000 data. Boundaries for urban areas have not been 45 | updated since Census 2000. As a result, data for urban and rural 46 | areas from the ACS do not necessarily reflect the results of 47 | ongoing urbanization. 48 | 49 | 50 | Explanation of Symbols: 51 | 1. An '**' entry in the margin of error column indicates that 52 | either no sample observations or too few sample observations were 53 | available to compute a standard error and thus the margin of error. 54 | A statistical test is not appropriate. 55 | 56 | 2. An '-' entry in the estimate column indicates that either no 57 | sample observations or too few sample observations were available 58 | to compute an estimate, or a ratio of medians cannot be calculated 59 | because one or both of the median estimates falls in the lowest 60 | interval or upper interval of an open-ended distribution. 61 | 62 | 3. An '-' following a median estimate means the median falls in 63 | the lowest interval of an open-ended distribution. 64 | 65 | 4. An '+' following a median estimate means the median falls in 66 | the upper interval of an open-ended distribution. 67 | 68 | 5. An '***' entry in the margin of error column indicates that 69 | the median falls in the lowest interval or upper interval of an 70 | open-ended distribution. A statistical test is not appropriate. 71 | 72 | 6. An '*****' entry in the margin of error column indicates that 73 | the estimate is controlled. A statistical test for sampling 74 | variability is not appropriate. 75 | 76 | 77 | 78 | 79 | 7. An 'N' entry in the estimate and margin of error columns 80 | indicates that data for this geographic area cannot be displayed 81 | because the number of sample cases is too small. 82 | 83 | 8. An '(X)' means that the estimate is not applicable or not 84 | available. 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /Bar_Charts_Basics/data/ACS_08_3YR_S1903/ACS_08_3YR_S1903_ann.csv: -------------------------------------------------------------------------------- 1 | GEO.id,GEO.id2,GEO.display-label,HC01_EST_VC02,HC01_MOE_VC02,HC02_EST_VC02,HC02_MOE_VC02,HC01_EST_VC04,HC01_MOE_VC04,HC02_EST_VC04,HC02_MOE_VC04,HC01_EST_VC05,HC01_MOE_VC05,HC02_EST_VC05,HC02_MOE_VC05,HC01_EST_VC06,HC01_MOE_VC06,HC02_EST_VC06,HC02_MOE_VC06,HC01_EST_VC07,HC01_MOE_VC07,HC02_EST_VC07,HC02_MOE_VC07,HC01_EST_VC08,HC01_MOE_VC08,HC02_EST_VC08,HC02_MOE_VC08,HC01_EST_VC09,HC01_MOE_VC09,HC02_EST_VC09,HC02_MOE_VC09,HC01_EST_VC10,HC01_MOE_VC10,HC02_EST_VC10,HC02_MOE_VC10,HC01_EST_VC11,HC01_MOE_VC11,HC02_EST_VC11,HC02_MOE_VC11,HC01_EST_VC12,HC01_MOE_VC12,HC02_EST_VC12,HC02_MOE_VC12,HC01_EST_VC14,HC01_MOE_VC14,HC02_EST_VC14,HC02_MOE_VC14,HC01_EST_VC15,HC01_MOE_VC15,HC02_EST_VC15,HC02_MOE_VC15,HC01_EST_VC16,HC01_MOE_VC16,HC02_EST_VC16,HC02_MOE_VC16,HC01_EST_VC17,HC01_MOE_VC17,HC02_EST_VC17,HC02_MOE_VC17,HC01_EST_VC19,HC01_MOE_VC19,HC02_EST_VC19,HC02_MOE_VC19,HC01_EST_VC20,HC01_MOE_VC20,HC02_EST_VC20,HC02_MOE_VC20,HC01_EST_VC21,HC01_MOE_VC21,HC02_EST_VC21,HC02_MOE_VC21,HC01_EST_VC22,HC01_MOE_VC22,HC02_EST_VC22,HC02_MOE_VC22,HC01_EST_VC23,HC01_MOE_VC23,HC02_EST_VC23,HC02_MOE_VC23,HC01_EST_VC24,HC01_MOE_VC24,HC02_EST_VC24,HC02_MOE_VC24,HC01_EST_VC26,HC01_MOE_VC26,HC02_EST_VC26,HC02_MOE_VC26,HC01_EST_VC27,HC01_MOE_VC27,HC02_EST_VC27,HC02_MOE_VC27,HC01_EST_VC28,HC01_MOE_VC28,HC02_EST_VC28,HC02_MOE_VC28,HC01_EST_VC29,HC01_MOE_VC29,HC02_EST_VC29,HC02_MOE_VC29,HC01_EST_VC30,HC01_MOE_VC30,HC02_EST_VC30,HC02_MOE_VC30,HC01_EST_VC31,HC01_MOE_VC31,HC02_EST_VC31,HC02_MOE_VC31,HC01_EST_VC32,HC01_MOE_VC32,HC02_EST_VC32,HC02_MOE_VC32,HC01_EST_VC34,HC01_MOE_VC34,HC02_EST_VC34,HC02_MOE_VC34,HC01_EST_VC35,HC01_MOE_VC35,HC02_EST_VC35,HC02_MOE_VC35,HC01_EST_VC36,HC01_MOE_VC36,HC02_EST_VC36,HC02_MOE_VC36 2 | Id,Id2,Geography,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - White,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - White,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - White,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - White,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Black or African American,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Black or African American,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Black or African American,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Black or African American,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - American Indian and Alaska Native,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - American Indian and Alaska Native,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - American Indian and Alaska Native,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - American Indian and Alaska Native,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Asian,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Asian,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Asian,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Asian,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Native Hawaiian and Other Pacific Islander,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Native Hawaiian and Other Pacific Islander,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Native Hawaiian and Other Pacific Islander,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Native Hawaiian and Other Pacific Islander,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Some other race,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Some other race,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Some other race,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Some other race,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Two or more races,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Two or more races,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Two or more races,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Two or more races,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Hispanic or Latino origin (of any race),Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Hispanic or Latino origin (of any race),Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Hispanic or Latino origin (of any race),Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Hispanic or Latino origin (of any race),"Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - White alone, not Hispanic or Latino","Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - White alone, not Hispanic or Latino","Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - White alone, not Hispanic or Latino","Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - White alone, not Hispanic or Latino",Total; Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 15 to 24 years,Total; Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 15 to 24 years,Median income (dollars); Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 15 to 24 years,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 15 to 24 years,Total; Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 25 to 44 years,Total; Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 25 to 44 years,Median income (dollars); Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 25 to 44 years,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 25 to 44 years,Total; Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 45 to 64 years,Total; Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 45 to 64 years,Median income (dollars); Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 45 to 64 years,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 45 to 64 years,Total; Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 65 years and over,Total; Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 65 years and over,Median income (dollars); Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 65 years and over,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 65 years and over,Total; Estimate; FAMILIES - Families,Total; Margin of Error; FAMILIES - Families,Median income (dollars); Estimate; FAMILIES - Families,Median income (dollars); Margin of Error; FAMILIES - Families,Total; Estimate; FAMILIES - Families - With own children under 18 years,Total; Margin of Error; FAMILIES - Families - With own children under 18 years,Median income (dollars); Estimate; FAMILIES - Families - With own children under 18 years,Median income (dollars); Margin of Error; FAMILIES - Families - With own children under 18 years,Total; Estimate; FAMILIES - Families - With no own children under 18 years,Total; Margin of Error; FAMILIES - Families - With no own children under 18 years,Median income (dollars); Estimate; FAMILIES - Families - With no own children under 18 years,Median income (dollars); Margin of Error; FAMILIES - Families - With no own children under 18 years,Total; Estimate; FAMILIES - Families - Married-couple families,Total; Margin of Error; FAMILIES - Families - Married-couple families,Median income (dollars); Estimate; FAMILIES - Families - Married-couple families,Median income (dollars); Margin of Error; FAMILIES - Families - Married-couple families,"Total; Estimate; FAMILIES - Families - Female householder, no husband present","Total; Margin of Error; FAMILIES - Families - Female householder, no husband present","Median income (dollars); Estimate; FAMILIES - Families - Female householder, no husband present","Median income (dollars); Margin of Error; FAMILIES - Families - Female householder, no husband present","Total; Estimate; FAMILIES - Families - Male householder, no wife present","Total; Margin of Error; FAMILIES - Families - Male householder, no wife present","Median income (dollars); Estimate; FAMILIES - Families - Male householder, no wife present","Median income (dollars); Margin of Error; FAMILIES - Families - Male householder, no wife present",Total; Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households,Total; Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households,Median income (dollars); Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households,Median income (dollars); Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households,Total; Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder,Total; Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder,Median income (dollars); Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder,Median income (dollars); Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder,Total; Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Living alone,Total; Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Living alone,Median income (dollars); Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Living alone,Median income (dollars); Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Living alone,Total; Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Not living alone,Total; Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Not living alone,Median income (dollars); Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Not living alone,Median income (dollars); Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Not living alone,Total; Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder,Total; Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder,Median income (dollars); Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder,Median income (dollars); Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder,Total; Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Living alone,Total; Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Living alone,Median income (dollars); Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Living alone,Median income (dollars); Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Living alone,Total; Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Not living alone,Total; Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Not living alone,Median income (dollars); Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Not living alone,Median income (dollars); Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Not living alone,Total; Estimate; PERCENT IMPUTED - Household income in the past 12 months,Total; Margin of Error; PERCENT IMPUTED - Household income in the past 12 months,Median income (dollars); Estimate; PERCENT IMPUTED - Household income in the past 12 months,Median income (dollars); Margin of Error; PERCENT IMPUTED - Household income in the past 12 months,Total; Estimate; PERCENT IMPUTED - Family income in the past 12 months,Total; Margin of Error; PERCENT IMPUTED - Family income in the past 12 months,Median income (dollars); Estimate; PERCENT IMPUTED - Family income in the past 12 months,Median income (dollars); Margin of Error; PERCENT IMPUTED - Family income in the past 12 months,Total; Estimate; PERCENT IMPUTED - Nonfamily income in the past 12 months,Total; Margin of Error; PERCENT IMPUTED - Nonfamily income in the past 12 months,Median income (dollars); Estimate; PERCENT IMPUTED - Nonfamily income in the past 12 months,Median income (dollars); Margin of Error; PERCENT IMPUTED - Nonfamily income in the past 12 months 3 | 0400000US01,01,Alabama,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 4 | 0400000US02,02,Alaska,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 5 | 0400000US04,04,Arizona,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 6 | 0400000US05,05,Arkansas,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 7 | 0400000US06,06,California,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 8 | 0400000US08,08,Colorado,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 9 | 0400000US09,09,Connecticut,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 10 | 0400000US10,10,Delaware,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 11 | 0400000US11,11,District of Columbia,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 12 | 0400000US12,12,Florida,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 13 | 0400000US13,13,Georgia,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 14 | 0400000US15,15,Hawaii,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 15 | 0400000US16,16,Idaho,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 16 | 0400000US17,17,Illinois,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 17 | 0400000US18,18,Indiana,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 18 | 0400000US19,19,Iowa,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 19 | 0400000US20,20,Kansas,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 20 | 0400000US21,21,Kentucky,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 21 | 0400000US22,22,Louisiana,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 22 | 0400000US23,23,Maine,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 23 | 0400000US24,24,Maryland,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 24 | 0400000US25,25,Massachusetts,,,,,,,,,,,,,,,,,,,,,$N,$N,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 25 | 0400000US26,26,Michigan,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 26 | 0400000US27,27,Minnesota,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 27 | 0400000US28,28,Mississippi,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 28 | 0400000US29,29,Missouri,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 29 | 0400000US30,30,Montana,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 30 | 0400000US31,31,Nebraska,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 31 | 0400000US32,32,Nevada,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 32 | 0400000US33,33,New Hampshire,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 33 | 0400000US34,34,New Jersey,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 34 | 0400000US35,35,New Mexico,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 35 | 0400000US36,36,New York,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 36 | 0400000US37,37,North Carolina,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 37 | 0400000US38,38,North Dakota,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 38 | 0400000US39,39,Ohio,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 39 | 0400000US40,40,Oklahoma,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 40 | 0400000US41,41,Oregon,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 41 | 0400000US42,42,Pennsylvania,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 42 | 0400000US44,44,Rhode Island,,,,,,,,,,,,,,,,,,,,,$N,$N,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 43 | 0400000US45,45,South Carolina,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 44 | 0400000US46,46,South Dakota,,,,,,,,,,,,,,,,,,,,,$N,$N,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 45 | 0400000US47,47,Tennessee,,,,,,,,,,,,,,,,,,,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 46 | 0400000US48,48,Texas,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 47 | 0400000US49,49,Utah,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 48 | 0400000US50,50,Vermont,,,,,,,,,,,,,,,,,,,,,$N,$N,$N,$N,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 49 | 0400000US51,51,Virginia,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 50 | 0400000US53,53,Washington,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 51 | 0400000US54,54,West Virginia,,,,,,,,,,,,,,,,,,,,,$N,$N,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 52 | 0400000US55,55,Wisconsin,,,,,,,,,,,,,,,,,,,,,$N,$N,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 53 | 0400000US56,56,Wyoming,,,,,,,,,$N,$N,,,,,,,$N,$N,,,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 54 | 0400000US72,72,Puerto Rico,,,,,,,,,,,,,,,,,,,,,$N,$N,$N,$N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,$(X),,$(X),,$(X),,$(X),,$(X),,$(X) 55 | -------------------------------------------------------------------------------- /Bar_Charts_Basics/data/ACS_08_3YR_S1903/ACS_08_3YR_S1903_metadata.csv: -------------------------------------------------------------------------------- 1 | GEO.id,Id 2 | GEO.id2,Id2 3 | GEO.display-label,Geography 4 | HC01_EST_VC02,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households 5 | HC01_MOE_VC02,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households 6 | HC02_EST_VC02,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households 7 | HC02_MOE_VC02,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households 8 | HC01_EST_VC04,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - White 9 | HC01_MOE_VC04,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - White 10 | HC02_EST_VC04,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - White 11 | HC02_MOE_VC04,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - White 12 | HC01_EST_VC05,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Black or African American 13 | HC01_MOE_VC05,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Black or African American 14 | HC02_EST_VC05,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Black or African American 15 | HC02_MOE_VC05,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Black or African American 16 | HC01_EST_VC06,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - American Indian and Alaska Native 17 | HC01_MOE_VC06,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - American Indian and Alaska Native 18 | HC02_EST_VC06,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - American Indian and Alaska Native 19 | HC02_MOE_VC06,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - American Indian and Alaska Native 20 | HC01_EST_VC07,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Asian 21 | HC01_MOE_VC07,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Asian 22 | HC02_EST_VC07,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Asian 23 | HC02_MOE_VC07,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Asian 24 | HC01_EST_VC08,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Native Hawaiian and Other Pacific Islander 25 | HC01_MOE_VC08,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Native Hawaiian and Other Pacific Islander 26 | HC02_EST_VC08,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Native Hawaiian and Other Pacific Islander 27 | HC02_MOE_VC08,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Native Hawaiian and Other Pacific Islander 28 | HC01_EST_VC09,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Some other race 29 | HC01_MOE_VC09,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Some other race 30 | HC02_EST_VC09,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Some other race 31 | HC02_MOE_VC09,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - One race-- - Some other race 32 | HC01_EST_VC10,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Two or more races 33 | HC01_MOE_VC10,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Two or more races 34 | HC02_EST_VC10,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Two or more races 35 | HC02_MOE_VC10,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Two or more races 36 | HC01_EST_VC11,Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Hispanic or Latino origin (of any race) 37 | HC01_MOE_VC11,Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Hispanic or Latino origin (of any race) 38 | HC02_EST_VC11,Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Hispanic or Latino origin (of any race) 39 | HC02_MOE_VC11,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - Hispanic or Latino origin (of any race) 40 | HC01_EST_VC12,"Total; Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - White alone, not Hispanic or Latino" 41 | HC01_MOE_VC12,"Total; Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - White alone, not Hispanic or Latino" 42 | HC02_EST_VC12,"Median income (dollars); Estimate; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - White alone, not Hispanic or Latino" 43 | HC02_MOE_VC12,"Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY RACE AND HISPANIC OR LATINO ORIGIN OF HOUSEHOLDER - Households - White alone, not Hispanic or Latino" 44 | HC01_EST_VC14,Total; Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 15 to 24 years 45 | HC01_MOE_VC14,Total; Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 15 to 24 years 46 | HC02_EST_VC14,Median income (dollars); Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 15 to 24 years 47 | HC02_MOE_VC14,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 15 to 24 years 48 | HC01_EST_VC15,Total; Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 25 to 44 years 49 | HC01_MOE_VC15,Total; Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 25 to 44 years 50 | HC02_EST_VC15,Median income (dollars); Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 25 to 44 years 51 | HC02_MOE_VC15,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 25 to 44 years 52 | HC01_EST_VC16,Total; Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 45 to 64 years 53 | HC01_MOE_VC16,Total; Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 45 to 64 years 54 | HC02_EST_VC16,Median income (dollars); Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 45 to 64 years 55 | HC02_MOE_VC16,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 45 to 64 years 56 | HC01_EST_VC17,Total; Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 65 years and over 57 | HC01_MOE_VC17,Total; Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 65 years and over 58 | HC02_EST_VC17,Median income (dollars); Estimate; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 65 years and over 59 | HC02_MOE_VC17,Median income (dollars); Margin of Error; HOUSEHOLD INCOME BY AGE OF HOUSEHOLDER - 65 years and over 60 | HC01_EST_VC19,Total; Estimate; FAMILIES - Families 61 | HC01_MOE_VC19,Total; Margin of Error; FAMILIES - Families 62 | HC02_EST_VC19,Median income (dollars); Estimate; FAMILIES - Families 63 | HC02_MOE_VC19,Median income (dollars); Margin of Error; FAMILIES - Families 64 | HC01_EST_VC20,Total; Estimate; FAMILIES - Families - With own children under 18 years 65 | HC01_MOE_VC20,Total; Margin of Error; FAMILIES - Families - With own children under 18 years 66 | HC02_EST_VC20,Median income (dollars); Estimate; FAMILIES - Families - With own children under 18 years 67 | HC02_MOE_VC20,Median income (dollars); Margin of Error; FAMILIES - Families - With own children under 18 years 68 | HC01_EST_VC21,Total; Estimate; FAMILIES - Families - With no own children under 18 years 69 | HC01_MOE_VC21,Total; Margin of Error; FAMILIES - Families - With no own children under 18 years 70 | HC02_EST_VC21,Median income (dollars); Estimate; FAMILIES - Families - With no own children under 18 years 71 | HC02_MOE_VC21,Median income (dollars); Margin of Error; FAMILIES - Families - With no own children under 18 years 72 | HC01_EST_VC22,Total; Estimate; FAMILIES - Families - Married-couple families 73 | HC01_MOE_VC22,Total; Margin of Error; FAMILIES - Families - Married-couple families 74 | HC02_EST_VC22,Median income (dollars); Estimate; FAMILIES - Families - Married-couple families 75 | HC02_MOE_VC22,Median income (dollars); Margin of Error; FAMILIES - Families - Married-couple families 76 | HC01_EST_VC23,"Total; Estimate; FAMILIES - Families - Female householder, no husband present" 77 | HC01_MOE_VC23,"Total; Margin of Error; FAMILIES - Families - Female householder, no husband present" 78 | HC02_EST_VC23,"Median income (dollars); Estimate; FAMILIES - Families - Female householder, no husband present" 79 | HC02_MOE_VC23,"Median income (dollars); Margin of Error; FAMILIES - Families - Female householder, no husband present" 80 | HC01_EST_VC24,"Total; Estimate; FAMILIES - Families - Male householder, no wife present" 81 | HC01_MOE_VC24,"Total; Margin of Error; FAMILIES - Families - Male householder, no wife present" 82 | HC02_EST_VC24,"Median income (dollars); Estimate; FAMILIES - Families - Male householder, no wife present" 83 | HC02_MOE_VC24,"Median income (dollars); Margin of Error; FAMILIES - Families - Male householder, no wife present" 84 | HC01_EST_VC26,Total; Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households 85 | HC01_MOE_VC26,Total; Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households 86 | HC02_EST_VC26,Median income (dollars); Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households 87 | HC02_MOE_VC26,Median income (dollars); Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households 88 | HC01_EST_VC27,Total; Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder 89 | HC01_MOE_VC27,Total; Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder 90 | HC02_EST_VC27,Median income (dollars); Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder 91 | HC02_MOE_VC27,Median income (dollars); Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder 92 | HC01_EST_VC28,Total; Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Living alone 93 | HC01_MOE_VC28,Total; Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Living alone 94 | HC02_EST_VC28,Median income (dollars); Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Living alone 95 | HC02_MOE_VC28,Median income (dollars); Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Living alone 96 | HC01_EST_VC29,Total; Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Not living alone 97 | HC01_MOE_VC29,Total; Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Not living alone 98 | HC02_EST_VC29,Median income (dollars); Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Not living alone 99 | HC02_MOE_VC29,Median income (dollars); Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Female householder - Not living alone 100 | HC01_EST_VC30,Total; Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder 101 | HC01_MOE_VC30,Total; Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder 102 | HC02_EST_VC30,Median income (dollars); Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder 103 | HC02_MOE_VC30,Median income (dollars); Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder 104 | HC01_EST_VC31,Total; Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Living alone 105 | HC01_MOE_VC31,Total; Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Living alone 106 | HC02_EST_VC31,Median income (dollars); Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Living alone 107 | HC02_MOE_VC31,Median income (dollars); Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Living alone 108 | HC01_EST_VC32,Total; Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Not living alone 109 | HC01_MOE_VC32,Total; Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Not living alone 110 | HC02_EST_VC32,Median income (dollars); Estimate; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Not living alone 111 | HC02_MOE_VC32,Median income (dollars); Margin of Error; NONFAMILY HOUSEHOLDS - Nonfamily households - Male householder - Not living alone 112 | HC01_EST_VC34,Total; Estimate; PERCENT IMPUTED - Household income in the past 12 months 113 | HC01_MOE_VC34,Total; Margin of Error; PERCENT IMPUTED - Household income in the past 12 months 114 | HC02_EST_VC34,Median income (dollars); Estimate; PERCENT IMPUTED - Household income in the past 12 months 115 | HC02_MOE_VC34,Median income (dollars); Margin of Error; PERCENT IMPUTED - Household income in the past 12 months 116 | HC01_EST_VC35,Total; Estimate; PERCENT IMPUTED - Family income in the past 12 months 117 | HC01_MOE_VC35,Total; Margin of Error; PERCENT IMPUTED - Family income in the past 12 months 118 | HC02_EST_VC35,Median income (dollars); Estimate; PERCENT IMPUTED - Family income in the past 12 months 119 | HC02_MOE_VC35,Median income (dollars); Margin of Error; PERCENT IMPUTED - Family income in the past 12 months 120 | HC01_EST_VC36,Total; Estimate; PERCENT IMPUTED - Nonfamily income in the past 12 months 121 | HC01_MOE_VC36,Total; Margin of Error; PERCENT IMPUTED - Nonfamily income in the past 12 months 122 | HC02_EST_VC36,Median income (dollars); Estimate; PERCENT IMPUTED - Nonfamily income in the past 12 months 123 | HC02_MOE_VC36,Median income (dollars); Margin of Error; PERCENT IMPUTED - Nonfamily income in the past 12 months 124 | -------------------------------------------------------------------------------- /Bar_Charts_Basics/data/ACS_08_3YR_S1903/aff_download_readme.txt: -------------------------------------------------------------------------------- 1 | 2 | This zip file contains a number of documents containing materials related to the table which you have downloaded. These include: 3 | 1. aff_download_readme.txt (this file) 4 | 2. .csv (data file) 5 | 3. _ann.csv (annotation file, if applicable) 6 | 4. .txt (notes file) 7 | 5. _metadata.csv (metadata file) 8 | 9 | Naming convention: 10 | 11 | The table file name is based on the Table Id. 12 | For Geographic Comparison Tables (GCT) and Geographic Ranking Tables (GRT), the table file name is based on Table ID and Stub. 13 | 14 | 15 | Document descriptions: 16 | 17 | Data file: 18 | file name: .csv 19 | Includes the tabular data for the table. 20 | 21 | Annotation file: 22 | file name: _ann.csv 23 | This file contains cell annotations, which could be simple jam values, flag symbols, or codes of more complex cell annotations that replace the values in the data file. This file has a parallel structure to the data file, but it includes only those lines that correspond to the lines from the data file that have annotations. If there are no lines to be included in the annotation file, then the whole annotation file is omitted. A cell annotation starts with '$' or 'ECONF$', and the string that follows the '$' char is the jamming string or flag symbol. For example, '$1000+' is a simple cell annotation that would replace the content of the cell with the string '1000+'. A cell annotation that does not start with '$', such as 'ECONF$', is a code that is described in the notes file (see below). 24 | 25 | Notes file: 26 | file name: .txt 27 | This file contains the head notes, footnotes and the description of the cell annotations occurring in the data file (simple jamming cell annotations are excluded). 28 | 29 | Metadata file: 30 | file name: _metadata.csv 31 | This file contains the header information (transposed), without the data associated with the table. -------------------------------------------------------------------------------- /Bar_Charts_Basics/data/income-2008-13.csv: -------------------------------------------------------------------------------- 1 | "FIPS","med2008","moe2008","med2013","moe2013" 2 | "01",42131,275,43253,241 3 | "02",66293,1129,70760,732 4 | "04",51124,309,49774,253 5 | "05",39127,349,40768,330 6 | "06",61154,173,61094,157 7 | "08",56574,345,58433,314 8 | "09",68411,584,69461,411 9 | "10",57270,944,59878,714 10 | "11",56428,1383,65830,1006 11 | "12",48637,157,46956,149 12 | "13",50549,281,49179,208 13 | "15",66034,932,67402,734 14 | "16",47331,581,46767,413 15 | "17",55935,225,56797,190 16 | "18",48675,283,48248,198 17 | "19",48585,318,51843,258 18 | "20",49189,388,51332,304 19 | "21",41763,277,43036,250 20 | "22",42634,333,44874,251 21 | "23",46807,530,48453,521 22 | "24",70005,421,73538,404 23 | "25",64684,361,66866,318 24 | "26",49694,215,48411,163 25 | "27",57795,275,59836,236 26 | "28",37404,446,39031,319 27 | "29",46408,274,47380,216 28 | "30",44042,537,46230,453 29 | "31",49231,412,51672,325 30 | "32",56348,529,52800,389 31 | "33",63989,596,64916,611 32 | "34",69674,354,71629,303 33 | "35",43202,539,44927,432 34 | "36",55401,210,58003,204 35 | "37",46107,236,46334,196 36 | "38",45390,623,53741,572 37 | "39",48023,152,48308,197 38 | "40",42541,309,45339,196 39 | "41",49863,339,50229,278 40 | "42",50272,193,52548,165 41 | "44",55327,836,56361,645 42 | "45",44326,297,44779,250 43 | "46",45542,534,49495,516 44 | "47",43662,255,44298,222 45 | "48",49078,190,51900,132 46 | "49",56484,419,58821,388 47 | "50",51704,682,54267,548 48 | "51",61044,347,63907,248 49 | "53",57234,356,59478,291 50 | "54",37870,342,41043,338 51 | "55",52249,216,52413,173 52 | "56",53096,918,57406,841 53 | "72",18610,163,19624,137 54 | -------------------------------------------------------------------------------- /Bar_Charts_Basics/data/income-totals.csv: -------------------------------------------------------------------------------- 1 | "id","FIPS","name","households","households_moe","med_income","med_income_moe","med_min","med_max" 2 | "0400000US01","01","Alabama",1838683,5863,43253,241,43012,43494 3 | "0400000US02","02","Alaska",251899,1331,70760,732,70028,71492 4 | "0400000US04","04","Arizona",2370289,8769,49774,253,49521,50027 5 | "0400000US05","05","Arkansas",1129723,4304,40768,330,40438,41098 6 | "0400000US06","06","California",12542460,20542,61094,157,60937,61251 7 | "0400000US08","08","Colorado",1977591,4762,58433,314,58119,58747 8 | "0400000US09","09","Connecticut",1355849,3506,69461,411,69050,69872 9 | "0400000US10","10","Delaware",335707,1773,59878,714,59164,60592 10 | "0400000US11","11","District of Columbia",263649,1588,65830,1006,64824,66836 11 | "0400000US12","12","Florida",7158980,25790,46956,149,46807,47105 12 | "0400000US13","13","Georgia",3518097,10972,49179,208,48971,49387 13 | "0400000US15","15","Hawaii",449771,1783,67402,734,66668,68136 14 | "0400000US16","16","Idaho",579797,2551,46767,413,46354,47180 15 | "0400000US17","17","Illinois",4772723,11056,56797,190,56607,56987 16 | "0400000US18","18","Indiana",2481793,6580,48248,198,48050,48446 17 | "0400000US19","19","Iowa",1226547,3433,51843,258,51585,52101 18 | "0400000US20","20","Kansas",1110440,3304,51332,304,51028,51636 19 | "0400000US21","21","Kentucky",1694996,5311,43036,250,42786,43286 20 | "0400000US22","22","Louisiana",1707852,5031,44874,251,44623,45125 21 | "0400000US23","23","Maine",553823,2219,48453,521,47932,48974 22 | "0400000US24","24","Maryland",2146240,5641,73538,404,73134,73942 23 | "0400000US25","25","Massachusetts",2530147,5224,66866,318,66548,67184 24 | "0400000US26","26","Michigan",3823280,8829,48411,163,48248,48574 25 | "0400000US27","27","Minnesota",2107232,5485,59836,236,59600,60072 26 | "0400000US28","28","Mississippi",1088073,4665,39031,319,38712,39350 27 | "0400000US29","29","Missouri",2360131,6252,47380,216,47164,47596 28 | "0400000US30","30","Montana",405525,2059,46230,453,45777,46683 29 | "0400000US31","31","Nebraska",725787,2583,51672,325,51347,51997 30 | "0400000US32","32","Nevada",999016,4087,52800,389,52411,53189 31 | "0400000US33","33","New Hampshire",518245,2172,64916,611,64305,65527 32 | "0400000US34","34","New Jersey",3186418,6092,71629,303,71326,71932 33 | "0400000US35","35","New Mexico",761938,3017,44927,432,44495,45359 34 | "0400000US36","36","New York",7234743,12096,58003,204,57799,58207 35 | "0400000US37","37","North Carolina",3715565,9398,46334,196,46138,46530 36 | "0400000US38","38","North Dakota",287270,1270,53741,572,53169,54313 37 | "0400000US39","39","Ohio",4557655,12660,48308,197,48111,48505 38 | "0400000US40","40","Oklahoma",1444081,3776,45339,196,45143,45535 39 | "0400000US41","41","Oregon",1516456,4721,50229,278,49951,50507 40 | "0400000US42","42","Pennsylvania",4958427,8583,52548,165,52383,52713 41 | "0400000US44","44","Rhode Island",410058,1761,56361,645,55716,57006 42 | "0400000US45","45","South Carolina",1780251,5580,44779,250,44529,45029 43 | "0400000US46","46","South Dakota",323136,1682,49495,516,48979,50011 44 | "0400000US47","47","Tennessee",2475195,6759,44298,222,44076,44520 45 | "0400000US48","48","Texas",8886471,18279,51900,132,51768,52032 46 | "0400000US49","49","Utah",886770,2762,58821,388,58433,59209 47 | "0400000US50","50","Vermont",257004,1218,54267,548,53719,54815 48 | "0400000US51","51","Virginia",3022739,8232,63907,248,63659,64155 49 | "0400000US53","53","Washington",2629126,5804,59478,291,59187,59769 50 | "0400000US54","54","West Virginia",741390,3047,41043,338,40705,41381 51 | "0400000US55","55","Wisconsin",2288332,6551,52413,173,52240,52586 52 | "0400000US56","56","Wyoming",222846,1618,57406,841,56565,58247 53 | "0400000US72","72","Puerto Rico",1230868,3660,19624,137,19487,19761 54 | -------------------------------------------------------------------------------- /Bar_Charts_Basics/data/state_geocodes_v2011.csv: -------------------------------------------------------------------------------- 1 | Region,Division,FIPS,Name 1,0,00,Northeast Region 1,1,00,New England Division 1,1,09,Connecticut 1,1,23,Maine 1,1,25,Massachusetts 1,1,33,New Hampshire 1,1,44,Rhode Island 1,1,50,Vermont 1,2,00,Middle Atlantic Division 1,2,34,New Jersey 1,2,36,New York 1,2,42,Pennsylvania 2,0,00,Midwest Region 2,3,00,East North Central Division 2,3,17,Illinois 2,3,18,Indiana 2,3,26,Michigan 2,3,39,Ohio 2,3,55,Wisconsin 2,4,00,West North Central Division 2,4,19,Iowa 2,4,20,Kansas 2,4,27,Minnesota 2,4,29,Missouri 2,4,31,Nebraska 2,4,38,North Dakota 2,4,46,South Dakota 3,0,00,South Region 3,5,00,South Atlantic Division 3,5,10,Delaware 3,5,11,District of Columbia 3,5,12,Florida 3,5,13,Georgia 3,5,24,Maryland 3,5,37,North Carolina 3,5,45,South Carolina 3,5,51,Virginia 3,5,54,West Virginia 3,6,00,East South Central Division 3,6,01,Alabama 3,6,21,Kentucky 3,6,28,Mississippi 3,6,47,Tennessee 3,7,00,West South Central Division 3,7,05,Arkansas 3,7,22,Louisiana 3,7,40,Oklahoma 3,7,48,Texas 4,0,00,West Region 4,8,00,Mountain Division 4,8,04,Arizona 4,8,08,Colorado 4,8,16,Idaho 4,8,30,Montana 4,8,32,Nevada 4,8,35,New Mexico 4,8,49,Utah 4,8,56,Wyoming 4,9,00,Pacific Division 4,9,02,Alaska 4,9,06,California 4,9,15,Hawaii 4,9,41,Oregon 4,9,53,Washington -------------------------------------------------------------------------------- /Bubbles_Chart/bubbles.R: -------------------------------------------------------------------------------- 1 | # Load data 2 | crime <- read.csv("crimeRatesByState2008.csv", header=TRUE, sep="\t") 3 | symbols(crime$murder, crime$burglary, circles=1) 4 | 5 | # Wrong sizes for radius 6 | symbols(crime$murder, crime$burglary, circles=crime$population/1000) 7 | 8 | # Correctly sized bubbles 9 | radius <- sqrt( crime$population/ pi ) 10 | symbols(crime$murder, crime$burglary, circles=radius) 11 | 12 | # Try squares 13 | symbols(crime$murder, crime$burglary, squares=sqrt(crime$population), inches=0.5) 14 | 15 | # Size circles smaller 16 | symbols(crime$murder, crime$burglary, circles=radius, inches=0.35, fg="white", bg="red", xlab="Murder Rate", ylab="Burglary Rate") 17 | 18 | # Add labels 19 | text(crime$murder, crime$burglary, crime$state, cex=0.5) 20 | -------------------------------------------------------------------------------- /Bubbles_Chart/crimeRatesByState2008.csv: -------------------------------------------------------------------------------- 1 | state murder Forcible_rate Robbery aggravated_assult burglary larceny_theft motor_vehicle_theft population Alabama 8.2 34.3 141.4 247.8 953.8 2650 288.3 4627851 Alaska 4.8 81.1 80.9 465.1 622.5 2599.1 391 686293 Arizona 7.5 33.8 144.4 327.4 948.4 2965.2 924.4 6500180 Arkansas 6.7 42.9 91.1 386.8 1084.6 2711.2 262.1 2855390 California 6.9 26 176.1 317.3 693.3 1916.5 712.8 36756666 Colorado 3.7 43.4 84.6 264.7 744.8 2735.2 559.5 4861515 Connecticut 2.9 20 113 138.6 437.1 1824.1 296.8 3501252 Delaware 4.4 44.7 154.8 428.2 688.9 2144 278.5 873092 Florida 5 37.1 169.4 496.6 926.3 2658.3 423.3 18328340 Georgia 6.2 23.6 154.8 264.3 931 2751.1 490.2 9685744 Hawaii 1.9 26.9 78.5 147.8 767.9 3308.4 716.4 1288198 Idaho 2.4 40.4 18.6 195.4 564.4 1931.7 201.8 1523816 Illinois 6 33.7 181.7 330.2 606.9 2164.8 308.6 12901563 Indiana 5.7 29.6 108.6 179.9 697.6 2412 346.7 6376792 Iowa 1.3 27.9 38.9 223.3 606.4 2042.7 184.6 3002555 Kansas 3.7 38.4 65.3 280 689.2 2758.1 339.6 2802134 Kentucky 4.6 34 88.4 139.8 634 1685.8 210.8 4269245 Louisiana 9.9 31.4 118 435.1 870.6 2494.5 318.1 4410796 Maine 1.4 24.7 24.4 61.7 478.5 1832.6 102 1316456 Maryland 9.9 22.6 256.7 413.8 641.4 2294.3 608.4 5633597 Massachusetts 2.7 27.1 119 308.1 541.1 1527.4 295.1 6497967 Michigan 6.1 51.3 131.8 362.9 696.8 1917.8 476.5 10003422 Minnesota 2.2 44 92 158.7 578.9 2226.9 278.2 5220393 Mississippi 7.3 39.3 82.3 149.4 919.7 2083.9 256.5 2938618 Missouri 6.9 28 124.1 366.4 738.3 2746.2 443.1 5911605 Montana 1.9 32.2 18.9 228.5 389.2 2543 210.7 967440 Nebraska 2.5 32.9 59.1 192.5 532.4 2574.3 316.5 1783432 Nevada 8.5 42.1 194.7 361.5 972.4 2153.9 1115.2 2600167 New Hampshire 1.4 30.9 27.4 72.3 317 1377.3 102.1 1315809 New Jersey 4.8 13.9 151.6 184.4 447.1 1568.4 317.5 8682661 New Mexico 7.4 54.1 98.7 541.9 1093.9 2639.9 414.5 1984356 New York 4.5 18.9 182.7 239.7 353.3 1569.6 185.6 19490297 North Carolina 6.7 26.5 145.5 289.4 1201.1 2546.2 327.8 9222414 North Dakota 1.1 24.2 7.4 65.5 311.9 1500.3 166 641481 Ohio 5.1 39.8 163.1 143.4 872.8 2429 360.9 11485910 Oklahoma 5.3 41.7 91 370.5 1006 2644.2 391.8 3642361 Oregon 2.2 34.8 68.1 181.8 758.6 3112.2 529 3790060 Pennsylvania 6.1 28.9 154.6 235 451.6 1729.1 236.5 12448279 Rhode Island 3.2 29.8 72.1 146.1 494.2 1816 408.7 1050788 South Carolina 7.4 42.5 132.1 579 1000.9 2954.1 384.4 4479800 South Dakota 2.3 46.7 18.6 108.1 324.4 1343.7 108.4 804194 Tennessee 7.2 36.4 167.3 541.9 1026.9 2828.1 420.6 6214888 Texas 6.2 37.2 156.6 329.8 961.6 2961.7 408.7 24326974 Utah 2.3 37.3 44.3 143.4 606.2 2918.8 343.9 2736424 Vermont 1.3 23.3 11.7 83.5 491.8 1686.1 102.9 621270 Virginia 6.1 22.7 99.2 154.8 392.1 2035 211.1 7769089 Washington 3.3 44.7 92.1 205.8 959.7 3149.5 783.9 6549224 West Virginia 4.4 17.7 44.6 206.1 621.2 1794 210 1814468 Wisconsin 3.5 20.6 82.2 135.2 440.8 1992.8 226.6 5627967 Wyoming 2.7 24 15.3 188.1 476.3 2533.9 145.1 532668 -------------------------------------------------------------------------------- /Bubbles_Chart/final-bubbles.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plissonf/FlowingData/7a7115de92496cd422714dc353aa0c8a0f76c9f4/Bubbles_Chart/final-bubbles.pdf -------------------------------------------------------------------------------- /Chernoff_faces/Crime Chernoff Faces by state-edited.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plissonf/FlowingData/7a7115de92496cd422714dc353aa0c8a0f76c9f4/Chernoff_faces/Crime Chernoff Faces by state-edited.pdf -------------------------------------------------------------------------------- /Chernoff_faces/chernoff.R: -------------------------------------------------------------------------------- 1 | library(aplpack) 2 | 3 | crime <- read.csv("http://datasets.flowingdata.com/crimeRatesByState-formatted.csv") 4 | faces(crime[,2:8]) 5 | 6 | crime_filled <- cbind(crime[,1:6], rep(0, length(crime$state)), crime[,7:8]) 7 | faces(crime_filled[,2:8]) 8 | faces(crime_filled[,2:8], labels=crime_filled$state) 9 | -------------------------------------------------------------------------------- /Chernoff_faces/data/.Rhistory: -------------------------------------------------------------------------------- 1 | map('county', 'united states') 2 | data(usaMapEnv) 3 | map('county', 'united states') 4 | map('county', 'usa') 5 | map('county', c('new jersey', 'california')) 6 | m <- map('county', c('new jersey', 'california')) 7 | m 8 | m <- map('county', c('new jersey', 'california'), fill=TRUE) 9 | m 10 | m <- map('county', c('new jersey', 'california'), fill=TRUE, col = palette()) 11 | m <- map('county', c('new jersey', 'california'), fill=TRUE, col = c("#FFF", "#000")) 12 | m <- map('county', c('new jersey', 'california'), fill=TRUE, col = c("#FFFFFF", "#000000")) 13 | m <- map('county', c('new jersey'), fill=TRUE, col = c("#FFFFFF", "#000000")) 14 | m <- map('county', c('new jersey'), fill=TRUE, col = c("#FFFFFF", "#666666")) 15 | m <- map('county', c('new jersey'), fill=TRUE, col = c("#FFFFFF", "#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#666666")) 16 | m <- map('county', c('new jersey,sussex'), fill=TRUE, col = c("#FFFFFF", "#666666")) 17 | m <- map('county', c('arizona,madison county'), fill=TRUE, col = c("#FFFFFF", "#666666")) 18 | m <- map('county', c('arizona,madison'), fill=TRUE, col = c("#FFFFFF", "#666666")) 19 | library(ggplot2) 20 | library(maps) 21 | county_df <- map_data("country") 22 | read.csv("http://datasets.flowingdata.com/ppg2008.csv", sep=",") 23 | nba <- read.csv("http://datasets.flowingdata.com/ppg2008.csv", sep=",") 24 | nba 25 | is.data.frame(nba) 26 | nba <- nba[order(nba$PTS),] 27 | ?heatmap 28 | nba_heatmap <- heatmap(nba_matrix, Rowv=NA, Colv=NA, col = cm.colors(256), scale="column", margins=c(5,10)) 29 | nba <- nba[order(nba$PTS),]# 30 | row.names(nba) <- nba$Name# 31 | nba <- nba[,2:20]# 32 | # 33 | nba_matrix <- data.matrix(nba) 34 | nba_heatmap <- heatmap(nba_matrix, Rowv=NA, Colv=NA, col = cm.colors(256), scale="column", margins=c(5,10)) 35 | install.packages("RColorBrewer") 36 | nba_heatmap <- heatmap(nba_matrix, Rowv=NA, Colv=NA, col = brewer.pal(9, "Blues"), scale="column", margins=c(5,10)) 37 | library("RColorBrewer") 38 | nba_heatmap <- heatmap(nba_matrix, Rowv=NA, Colv=NA, col = brewer.pal(9, "Blues"), scale="column", margins=c(5,10)) 39 | ?cm.colors 40 | nba_heatmap <- heatmap(nba_matrix, Rowv=NA, Colv=NA, col = heat.colors(256), scale="column", margins=c(5,10)) 41 | library(maptools) 42 | ?maptools 43 | library("RColorBrewer") 44 | ?brewer 45 | library(portfolio) 46 | data(dow.jan.2005) 47 | map.market(id = dow.jan.2005$symbol, area=dow.jan.2005$price, group=dow.jan.2005$sector) 48 | map.market(id = dow.jan.2005$symbol, area=dow.jan.2005$price, group=dow.jan.2005$sector, color=100*dow.jan.2005$month.ret) 49 | 100*dow.jan.2005$month.ret 50 | dow.jan.2005 51 | map.market(area=dow.jan.2005$price, group=dow.jan.2005$sector, color=100*dow.jan.2005$month.ret) 52 | map.market(id = dow.jan.2005$symbol, area=dow.jan.2005$price, group=dow.jan.2005$sector, color=100*dow.jan.2005$month.ret) 53 | map.market 54 | ?colorRamp 55 | data <- read.csv("http://datasets.flowingdata.com/post-data.txt") 56 | packages.install(portfolio) 57 | install.packages(portfolio) 58 | install.packages("portfolio") 59 | library(portfolio) 60 | map.market(id=data$id, area=data$views, group=data$category, color=data$comments, main="FlowingData Map") 61 | treemap <- function (id, area, group, color, scale = NULL, lab = c(TRUE, # 62 | FALSE), main = "Map of the Market", print = TRUE) # 63 | {# 64 | if (any(length(id) != length(area), length(id) != length(group), # 65 | length(id) != length(color))) {# 66 | stop("id, area, group, and color must be the same length.")# 67 | }# 68 | if (length(lab) == 1) {# 69 | lab[2] <- lab[1]# 70 | }# 71 | stopifnot(all(!is.na(id)))# 72 | data <- data.frame(label = id, group, area, color)# 73 | data <- data[order(data$area, decreasing = TRUE), ]# 74 | if (any(is.na(data$area) | is.na(data$group) | is.na(data$color))) {# 75 | warning("Stocks with NAs for area, group, or color will not be shown")# 76 | data <- subset(data, !is.na(area) & !is.na(group) & !is.na(color))# 77 | }# 78 | if (nrow(data) == 0) {# 79 | stop("No records to display")# 80 | }# 81 | data$color.orig <- data$color# 82 | if (is.null(scale)) {# 83 | data$color <- data$color * 1/max(abs(data$color))# 84 | }# 85 | else {# 86 | data$color <- data$color * 1/scale# 87 | }# 88 | data.by.group <- split(data, data$group, drop = TRUE)# 89 | group.data <- lapply(data.by.group, function(x) {# 90 | sum(x[, 3])# 91 | })# 92 | group.data <- data.frame(area = as.numeric(group.data), label = names(group.data))# 93 | group.data <- group.data[order(group.data$area, decreasing = TRUE), # 94 | ]# 95 | group.data$color <- rep(NULL, nrow(group.data))# 96 | color.ramp.pos <- colorRamp(c("white", "black"))# 97 | color.ramp.neg <- colorRamp(c("white", "red"))# 98 | color.ramp.rgb <- function(x) {# 99 | col.mat <- mapply(function(x) {# 100 | if (x < 0) {# 101 | color.ramp.neg(abs(x))# 102 | }# 103 | else {# 104 | color.ramp.pos(abs(x))# 105 | }# 106 | }, x)# 107 | mapply(rgb, col.mat[1, ], col.mat[2, ], col.mat[3, ], # 108 | max = 255)# 109 | }# 110 | add.viewport <- function(z, label, color, x.0, y.0, x.1, # 111 | y.1) {# 112 | for (i in 1:length(label)) {# 113 | if (is.null(color[i])) {# 114 | filler <- gpar(col = "blue", fill = "transparent", # 115 | cex = 1)# 116 | }# 117 | else {# 118 | filler.col <- color.ramp.rgb(color[i])# 119 | filler <- gpar(col = filler.col, fill = filler.col, # 120 | cex = 0.6)# 121 | }# 122 | new.viewport <- viewport(x = x.0[i], y = y.0[i], # 123 | width = (x.1[i] - x.0[i]), height = (y.1[i] - # 124 | y.0[i]), default.units = "npc", just = c("left", # 125 | "bottom"), name = as.character(label[i]), clip = "on", # 126 | gp = filler)# 127 | z <- append(z, list(new.viewport))# 128 | }# 129 | z# 130 | }# 131 | squarified.treemap <- function(z, x = 0, y = 0, w = 1, h = 1, # 132 | func = add.viewport, viewport.list) {# 133 | cz <- cumsum(z$area)/sum(z$area)# 134 | n <- which.min(abs(log(max(w/h, h/w) * sum(z$area) * # 135 | ((cz^2)/z$area))))# 136 | more <- n < length(z$area)# 137 | a <- c(0, cz[1:n])/cz[n]# 138 | if (h > w) {# 139 | viewport.list <- func(viewport.list, z$label[1:n], # 140 | z$color[1:n], x + w * a[1:(length(a) - 1)], rep(y, # 141 | n), x + w * a[-1], rep(y + h * cz[n], n))# 142 | if (more) {# 143 | viewport.list <- Recall(z[-(1:n), ], x, y + h * # 144 | cz[n], w, h * (1 - cz[n]), func, viewport.list)# 145 | }# 146 | }# 147 | else {# 148 | viewport.list <- func(viewport.list, z$label[1:n], # 149 | z$color[1:n], rep(x, n), y + h * a[1:(length(a) - # 150 | 1)], rep(x + w * cz[n], n), y + h * a[-1])# 151 | if (more) {# 152 | viewport.list <- Recall(z[-(1:n), ], x + w * # 153 | cz[n], y, w * (1 - cz[n]), h, func, viewport.list)# 154 | }# 155 | }# 156 | viewport.list# 157 | }# 158 | map.viewport <- viewport(x = 0.05, y = 0.05, width = 0.9, # 159 | height = 0.75, default.units = "npc", name = "MAP", just = c("left", # 160 | "bottom"))# 161 | map.tree <- gTree(vp = map.viewport, name = "MAP", children = gList(rectGrob(gp = gpar(col = "dark grey"), # 162 | name = "background")))# 163 | group.viewports <- squarified.treemap(z = group.data, viewport.list = list())# 164 | for (i in 1:length(group.viewports)) {# 165 | this.group <- data.by.group[[group.data$label[i]]]# 166 | this.data <- data.frame(this.group$area, this.group$label, # 167 | this.group$color)# 168 | names(this.data) <- c("area", "label", "color")# 169 | stock.viewports <- squarified.treemap(z = this.data, # 170 | viewport.list = list())# 171 | group.tree <- gTree(vp = group.viewports[[i]], name = group.data$label[i])# 172 | for (s in 1:length(stock.viewports)) {# 173 | stock.tree <- gTree(vp = stock.viewports[[s]], name = this.data$label[s], # 174 | children = gList(rectGrob(name = "color")))# 175 | if (lab[2]) {# 176 | stock.tree <- addGrob(stock.tree, textGrob(x = unit(1, # 177 | "lines"), y = unit(1, "npc") - unit(1, "lines"), # 178 | label = this.data$label[s], gp = gpar(col = "white"), # 179 | name = "label", just = c("left", "top")))# 180 | }# 181 | group.tree <- addGrob(group.tree, stock.tree)# 182 | }# 183 | group.tree <- addGrob(group.tree, rectGrob(gp = gpar(col = "grey"), # 184 | name = "border"))# 185 | if (lab[1]) {# 186 | group.tree <- addGrob(group.tree, textGrob(label = group.data$label[i], # 187 | name = "label", gp = gpar(col = "white")))# 188 | }# 189 | map.tree <- addGrob(map.tree, group.tree)# 190 | }# 191 | op <- options(digits = 1)# 192 | top.viewport <- viewport(x = 0.05, y = 1, width = 0.9, height = 0.2, # 193 | default.units = "npc", name = "TOP", , just = c("left", # 194 | "top"))# 195 | legend.ncols <- 51# 196 | l.x <- (0:(legend.ncols - 1))/(legend.ncols)# 197 | l.y <- unit(0.25, "npc")# 198 | l.cols <- color.ramp.rgb(seq(-1, 1, by = 2/(legend.ncols - # 199 | 1)))# 200 | l.end <- max(abs(data$color.orig))# 201 | top.list <- gList(textGrob(label = main, y = unit(0.7, "npc"), # 202 | just = c("center", "center"), gp = gpar(cex = 2)), segmentsGrob(x0 = seq(0, # 203 | 1, by = 0.25), y0 = unit(0.25, "npc"), x1 = seq(0, 1, # 204 | by = 0.25), y1 = unit(0.2, "npc")), rectGrob(x = l.x, # 205 | y = l.y, width = 1/legend.ncols, height = unit(1, "lines"), # 206 | just = c("left", "bottom"), gp = gpar(col = NA, fill = l.cols), # 207 | default.units = "npc"), textGrob(label = format(l.end * # 208 | seq(-1, 1, by = 0.5), trim = TRUE), x = seq(0, 1, by = 0.25), # 209 | y = 0.1, default.units = "npc", just = c("center", "center"), # 210 | gp = gpar(col = "black", cex = 0.8, fontface = "bold")))# 211 | options(op)# 212 | top.tree <- gTree(vp = top.viewport, name = "TOP", children = top.list)# 213 | mapmarket <- gTree(name = "MAPMARKET", children = gList(rectGrob(gp = gpar(col = "dark grey", # 214 | fill = "dark grey"), name = "background"), top.tree, # 215 | map.tree))# 216 | if (print) {# 217 | grid.newpage()# 218 | grid.draw(mapmarket)# 219 | }# 220 | invisible(mapmarket)# 221 | } 222 | treemap(id=data$id, area=data$views, group=data$category, color=data$comments, main="FlowingData Map") 223 | data <- read.csv("http://datasets.flowingdata.com/post-data.txt") 224 | library(portfolio) 225 | map.market(id=data$id, area=data$views, group=data$category, color=data$comments, main="FlowingData Map") 226 | data 227 | map.market(id=data$id, area=data$views, group=data$category, color=data$comments, main="FlowingData Map") 228 | ?runif 229 | runif(0, 100, 5) 230 | runif(10, 0, 1) 231 | runif(10, 0, 1) * 100 232 | round( runif(10, 0, 1) * 100, 0) 233 | round( runif(5, 0, 1) * 10, 0 ) 234 | round( runif(5, 0, 1) * 100, 0 ) 235 | r <- runif(5, 0, 1) * 100 236 | sum(r) 237 | r 238 | r / sum(r) 239 | r <- r / sum(r) * 100 240 | r 241 | r / sum(r) * 100 242 | round(r / sum(r) * 100) 243 | sum(round(r / sum(r)) * 100) 244 | round(r / sum(r)) 245 | sum(r) 246 | round(r / sum(r) * 100) 247 | sum( round(r / sum(r) * 100) ) 248 | r <- runif(5, 0, 1) * 100# 249 | round(r / sum(r) * 100) 250 | round(r / sum(r) * 100, 1) 251 | r <- runif(5, 0, 1) * 100# 252 | round(r / sum(r) * 100, 1) 253 | ?sample 254 | 10^2 255 | 1:10 256 | 1:10:2 257 | 1:2:10 258 | ?seq 259 | i = 1:10 260 | i 261 | si = 10 * 10^( (i-1)/2 ) 262 | si 263 | sample(si, 2, replace=FALSE) 264 | si = 10 * 10^( (i-1)/12 ) 265 | SI 266 | si 267 | sample(si, 2, replace=FALSE) 268 | round( runif(8, 0, 1) * 100 ) 269 | sample(si, 2, replace=FALSE) 270 | sample(si, 2, replace=FALSE)# 271 | round( runif(8, 0, 1) * 100 ) 272 | round( runif(8, 0.05, 1) * 100 ) 273 | runif(8, 0.05, 1) 274 | sample(si, 2, replace=FALSE)# 275 | round( runif(8, 0.05, 1) * 100 ) 276 | si 277 | sample(si, 2, replace=FALSE)# 278 | round( runif(8, 0.05, 1) * 100 ) 279 | sample(si, 2, replace=FALSE)# 280 | round( runif(8, 0.05, 1) * 50 ) 281 | sample(si, 2, replace=FALSE)# 282 | round( runif(8, 0.05, 1) * 35 ) 283 | sample(si, 2, replace=FALSE)# 284 | round( runif(8, 0.05, 1) * 20 ) 285 | round( runif(5, 0.05, 1) * 100 ) 286 | i = 1:10# 287 | si = 10 * 10^( (i-1)/12 )# 288 | sample(si, 2, replace=FALSE)# 289 | round( runif(3, 0.05, 1) * 100 ) 290 | sample(si, 2, replace=FALSE)# 291 | round( runif(3, 0.05, 1) * 100 ) 292 | ?scatter.smooth 293 | unemployment <- read.csv("http://datasets.flowingdata.com/unemployment-rate-1948-2010.csv", sep=",")# 294 | unemployment[1:10,] 295 | scatter.smooth(x=1:length(unemployment$Value), y=unemployment$Value) 296 | scatter.smooth(x=1:length(unemployment$Value), y=unemployment$Value, ylim=c(0,11)) 297 | scatter.smooth(x=1:length(unemployment$Value), y=unemployment$Value, ylim=c(0,11), col="#CCCCCC") 298 | n <- 2 299 | r_sort <- runif(n, 0, 1) * 100; sort( round(r_sort / sum(r_sort) * 100, 1), decreasing=T ) 300 | n <- 3 301 | r_sort <- runif(n, 0, 1) * 100; sort( round(r_sort / sum(r_sort) * 100, 1), decreasing=T ) 302 | n <- 4 303 | r_sort <- runif(n, 0, 1) * 100; sort( round(r_sort / sum(r_sort) * 100, 1), decreasing=T ) 304 | n <- 5 305 | r_sort <- runif(n, 0, 1) * 100; sort( round(r_sort / sum(r_sort) * 100, 1), decreasing=T ) 306 | n <- 6 307 | r_sort <- runif(n, 0, 1) * 100; sort( round(r_sort / sum(r_sort) * 100, 1), decreasing=T ) 308 | unemployment <- read.csv("http://datasets.flowingdata.com/unemployment-rate-1948-2010.csv", sep=",") 309 | p <- scatter.smooth(x=1:length(unemployment$Value), y=unemployment$Value) 310 | p 311 | p <- scatter.smooth(x=1:length(unemployment$Value), y=unemployment$Value) 312 | p 313 | ?scatter.smooth 314 | p <- loess.smooth(x=1:length(unemployment$Value), y=unemployment$Value) 315 | p 316 | loess.smooth(x=1:length(unemployment$Value), y=unemployment$Value) 317 | p$x 318 | crime_rates <- read.csv("crimeRatesByState-formatted.csv") 319 | library(aplpack) 320 | crime_rates[1:6,] 321 | faces(crime_rates[1:6, 2:8], labels=crime_rates[1:6]$state) 322 | cbind(crime_rates[1:6, 2:6], c(0,0,0,0,0,0), crime_rates[1:6, 7:8], labels=crime_rates[1:6]$state) 323 | cbind(crime_rates[1:6, 2:6], c(0,0,0,0,0,0), crime_rates[1:6, 7:8]) 324 | testing <- cbind(crime_rates[1:6, 2:6], c(0,0,0,0,0,0), crime_rates[1:6, 7:8]) 325 | faces(testing, labels=crime_rates[1:6]$state) 326 | ?rep 327 | rep(0, 4) 328 | rep(0, length(crime_reports$state)) 329 | rep(0, length(crime_rates$state)) 330 | crime_filled <- cbind(crime_rates[, 2:6], rep(0, length(crime_rates$state)), crime_rates[, 7:8]) 331 | crime_filled[1:2,] 332 | faces(crime_filled, labels=crime_filled$state) 333 | crime_filled 334 | crime_rates <- read.csv("crimeRatesByState-formatted.csv") 335 | crime_filled <- cbind(crime_rates[, 2:6], rep(0, length(crime_rates$state)), crime_rates[, 7:8]) 336 | faces(crime_filled, labels=crime_rates$state) 337 | faces(crime_filled, labels=crime_rates$state, nrow=5) 338 | faces(crime_filled, labels=crime_rates$state, nrow=5) 339 | faces(crime_filled, labels=crime_rates$state, nrow=5) 340 | faces(crime_filled, labels=crime_rates$state, nrow=10) 341 | faces(crime_filled, labels=crime_rates$state, ncol=5) 342 | faces(crime_filled, labels=crime_rates$state, ncol=6) 343 | faces(crime_filled, labels=crime_rates$state, ncol=6) 344 | faces(crime_filled, labels=crime_rates$state, ncol=7) 345 | crime_rates <- read.csv("crimeRatesByState-formatted.csv") 346 | crime_filled <- cbind(crime_rates[, 2:6], rep(0, length(crime_rates$state)), crime_rates[, 7:8]) 347 | face(crime_filled, labels=crime_filled$state) 348 | faces(crime_filled, labels=crime_filled$state) 349 | crime_filled <- cbind(crime_rates[, 1:6], rep(0, length(crime_rates$state)), crime_rates[, 7:8]) 350 | faces(crime_filled[,2:8], labels=crime_filled$state) 351 | faces(crime_filled[,2:8], labels=crime_filled$state, ncol=7) 352 | faces(crime_filled[,2:8], labels=crime_filled$state, ncol=7, scale=False) 353 | faces(crime_filled[,2:8], labels=crime_filled$state, ncol=7, scale=FALSE) 354 | faces(crime_filled[,2:8], labels=crime_filled$state, ncol=7) 355 | crime <- read.csv("http://datasets.flowingdata.com/crimeRatesByState-formatted.csv") 356 | faces(crime[,2:6], labels=crime$state) 357 | faces(crime[1:6,2:8], labels=crime$state) 358 | faces(crime[,2:8], labels=crime$state) 359 | crime_filled <- cbind(crime[,2:6], rep(0, length(crime$state), crime[,7:8]) 360 | ) 361 | crime_filled[1:4,] 362 | crime_filled <- cbind(crime[,1:6], rep(0, length(crime$state), crime[,7:8]) 363 | ) 364 | crime_filled[1:4,] 365 | crime_filled <- cbind(crime[,1:6], rep(0, length(crime$state), crime[,7:8]))# 366 | faces(crime_filled[,2:8]) 367 | crime_filled <- cbind(crime[,1:6], rep(0, length(crime$state), crime[,7:8])) 368 | faces(crime_filled[,2:8]) 369 | crime_filled[,2:8] 370 | crime_filled[1:4,] 371 | crime[1:2,] 372 | crime_filled <- cbind(crime[,1:6], rep(0, length(crime$state)), crime[,7:8]) 373 | faces(crime_filled[,2:8]) 374 | faces(crime_filled[,2:8], labels=crime_filled$state) 375 | library(aplpack) 376 | faces(crime[,2:8]) 377 | crime_filled <- cbind(crime[,1:6], rep(0, length(crime$state)), crime[,7:8])# 378 | faces(crime_filled[,2:8]) 379 | faces(crime_filled[,2:8], labels=crime_filled$state) 380 | -------------------------------------------------------------------------------- /Chernoff_faces/data/crimeRatesByState-formatted.csv: -------------------------------------------------------------------------------- 1 | state,murder,Forcible_rate,Robbery,aggravated_assult,burglary,larceny_theft,motor_vehicle_theft United States ,5.6,31.7,140.7,291.1,726.7,2286.3,416.7 Alabama ,8.2,34.3,141.4,247.8,953.8,2650.0,288.3 Alaska ,4.8,81.1,80.9,465.1,622.5,2599.1,391.0 Arizona ,7.5,33.8,144.4,327.4,948.4,2965.2,924.4 Arkansas,6.7,42.9,91.1,386.8,1084.6,2711.2,262.1 California ,6.9,26.0,176.1,317.3,693.3,1916.5,712.8 Colorado ,3.7,43.4,84.6,264.7,744.8,2735.2,559.5 Connecticut ,2.9,20.0,113.0,138.6,437.1,1824.1,296.8 Delaware ,4.4,44.7,154.8,428.2,688.9,2144.0,278.5 District of Columbia \3,35.4,30.2,672.1,721.3,649.7,2694.9,1402.3 Florida ,5.0,37.1,169.4,496.6,926.3,2658.3,423.3 Georgia ,6.2,23.6,154.8,264.3,931.0,2751.1,490.2 Hawaii ,1.9,26.9,78.5,147.8,767.9,3308.4,716.4 Idaho ,2.4,40.4,18.6,195.4,564.4,1931.7,201.8 Illinois ,6.0,33.7,181.7,330.2,606.9,2164.8,308.6 Indiana ,5.7,29.6,108.6,179.9,697.6,2412.0,346.7 Iowa ,1.3,27.9,38.9,223.3,606.4,2042.7,184.6 Kansas ,3.7,38.4,65.3,280.0,689.2,2758.1,339.6 Kentucky ,4.6,34.0,88.4,139.8,634.0,1685.8,210.8 Louisiana ,9.9,31.4,118.0,435.1,870.6,2494.5,318.1 Maine ,1.4,24.7,24.4,61.7,478.5,1832.6,102.0 Maryland ,9.9,22.6,256.7,413.8,641.4,2294.3,608.4 Massachusetts,2.7,27.1,119.0,308.1,541.1,1527.4,295.1 Michigan,6.1,51.3,131.8,362.9,696.8,1917.8,476.5 Minnesota ,2.2,44.0,92.0,158.7,578.9,2226.9,278.2 Mississippi ,7.3,39.3,82.3,149.4,919.7,2083.9,256.5 Missouri ,6.9,28.0,124.1,366.4,738.3,2746.2,443.1 Montana ,1.9,32.2,18.9,228.5,389.2,2543.0,210.7 Nebraska ,2.5,32.9,59.1,192.5,532.4,2574.3,316.5 Nevada ,8.5,42.1,194.7,361.5,972.4,2153.9,1115.2 New Hampshire ,1.4,30.9,27.4,72.3,317.0,1377.3,102.1 New Jersey,4.8,13.9,151.6,184.4,447.1,1568.4,317.5 New Mexico ,7.4,54.1,98.7,541.9,1093.9,2639.9,414.5 New York,4.5,18.9,182.7,239.7,353.3,1569.6,185.6 North Carolina ,6.7,26.5,145.5,289.4,1201.1,2546.2,327.8 North Dakota ,1.1,24.2,7.4,65.5,311.9,1500.3,166.0 Ohio ,5.1,39.8,163.1,143.4,872.8,2429.0,360.9 Oklahoma ,5.3,41.7,91.0,370.5,1006.0,2644.2,391.8 Oregon ,2.2,34.8,68.1,181.8,758.6,3112.2,529.0 Pennsylvania,6.1,28.9,154.6,235.0,451.6,1729.1,236.5 Rhode Island ,3.2,29.8,72.1,146.1,494.2,1816.0,408.7 South Carolina ,7.4,42.5,132.1,579.0,1000.9,2954.1,384.4 South Dakota ,2.3,46.7,18.6,108.1,324.4,1343.7,108.4 Tennessee ,7.2,36.4,167.3,541.9,1026.9,2828.1,420.6 Texas ,6.2,37.2,156.6,329.8,961.6,2961.7,408.7 Utah,2.3,37.3,44.3,143.4,606.2,2918.8,343.9 Vermont ,1.3,23.3,11.7,83.5,491.8,1686.1,102.9 Virginia ,6.1,22.7,99.2,154.8,392.1,2035.0,211.1 Washington ,3.3,44.7,92.1,205.8,959.7,3149.5,783.9 West Virginia ,4.4,17.7,44.6,206.1,621.2,1794.0,210.0 Wisconsin ,3.5,20.6,82.2,135.2,440.8,1992.8,226.6 Wyoming ,2.7,24.0,15.3,188.1,476.3,2533.9,145.1 -------------------------------------------------------------------------------- /Chernoff_faces/data/crimeRatesByState-formatted.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plissonf/FlowingData/7a7115de92496cd422714dc353aa0c8a0f76c9f4/Chernoff_faces/data/crimeRatesByState-formatted.xls -------------------------------------------------------------------------------- /Chernoff_faces/data/statab2008_0301_CrimeRatesByState2004And2005AndByTy.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plissonf/FlowingData/7a7115de92496cd422714dc353aa0c8a0f76c9f4/Chernoff_faces/data/statab2008_0301_CrimeRatesByState2004And2005AndByTy.xls -------------------------------------------------------------------------------- /Connected_Scatterplots/.Rhistory: -------------------------------------------------------------------------------- 1 | setwd("/Users/f.plisson/Desktop/Rworkspace/Datasets") 2 | getwd() 3 | setwd("/Users/fabienplisson/Documents/AAA_Capon Group/Chemometrics 2/Rworkspace/Datasets") 4 | setwd("./Documents/AAA_Capon Group/Chemometrics 2/Rworkspace/Datasets") 5 | ALL.df <- read.csv("./Datasets_Group2_17Apr2012.csv") row=compounds and columns=molecular properties/variables v1 to v29 6 | ALL.df <- read.csv("./Datasets_Group2_17Apr2012.csv") 7 | getwd() 8 | getwd("/Users/fabienplisson/Documents/AAA_Capon Group/BBB model//Chemoinformatics QSPR/Datasets/") 9 | getwd("./Documents/AAA_Capon Group/BBB model/Chemoinformatics QSPR/Datasets/") 10 | getwd() 11 | getwd("./Documents/AAA_Capon Group/BBB model/Chemoinformatics QSPR/") 12 | setwd("~/Documents/AAA_Capon Group/BBB model/Chemoinformatics QSPR/Rworkspace/Rscripts") 13 | setwd("~/") 14 | getwd() 15 | setwd("~/Documents/AAA_Capon Group/BBB model/Chemoinformatics QSPR/Datasets/") 16 | ALL.df <- read.csv("./Datasets_Group2_17Apr2012.csv") 17 | setwd("~/") 18 | getwd() 19 | source('~/.active-rstudio-document', echo=TRUE) 20 | source('~/.active-rstudio-document', echo=TRUE) 21 | .pardefault <- par() 22 | par(.pardefault) 23 | .pardefault <- par(no.readonly = T) 24 | source('~/.active-rstudio-document', echo=TRUE) 25 | par() 26 | setwd("~/Desktop/Github shares/FlowingData/Connected Scatterplots") 27 | jamie <- read.csv('jamie-counts.csv') 28 | jamie$fpct <- jamie$female / (jamie$female + jamie$male) 29 | jamie$mpct <- 1 - jamie$fpct 30 | # 31 | # Time series chart 32 | # 33 | plot(jamie$year, jamie$fpct, ylim=c(0,1)) 34 | lines(jamie$year, jamie$fpct) 35 | lines(c(1880,2012), c(0.5,0.5), col="red") 36 | plot(jamie[-(1:30), 2:3]) 37 | lines(jamie[-(1:30), 2:3]) 38 | lines(c(-1,13000), c(-1,13000), col="red") 39 | text(jamie[-(1:30), 2], jamie[-(1:30), 3]-100, jamie$year[-(1:30)], cex=0.5) 40 | plot(jamie[-(1:30), 2:3], log="xy") 41 | lines(jamie[-(1:30), 2:3]) 42 | lines(c(1,13000), c(1,13000), col="red") 43 | plot(jamie[-(1:30), 2:3], log="xy", bty="n", las=1, type="n") 44 | xTicks <- axTicks(1) 45 | yTicks <- axTicks(2) 46 | for (i in 1:length(xTicks)) { 47 | lines(c(xTicks[i], xTicks[i]), c(1, 1.5*max(yTicks)), col="#888888", lwd=0.5, lty=3) 48 | } 49 | for (j in 1:length(yTicks)) { 50 | lines(c(1, 1.5*max(xTicks)), c(yTicks[j], yTicks[j]), col="#888888", lwd=0.5, lty=3) 51 | } 52 | lines(jamie[-(1:30), 2:3]) 53 | points(jamie[-(1:30), 2:3], bg="#ffffff", pch=21, cex=0.8) 54 | # Labels 55 | text(jamie[-(1:30), 2], jamie[-(1:30), 3]-0.13*jamie[-(1:30), 3], jamie$year[-(1:30)], cex=0.5) 56 | connectedScatter <- function(x, y, labels=c(), log="", xlab="x", ylab="y") { 57 | plot(x, y, log=log, bty="n", las=1, type="n", xlab=xlab, ylab=ylab) 58 | xTicks <- axTicks(1) 59 | yTicks <- axTicks(2) 60 | for (i in 1:length(xTicks)) { 61 | lines(c(xTicks[i], xTicks[i]), c(1, 1.5*max(yTicks)), col="#888888", lwd=0.5, lty=3) 62 | } 63 | for (j in 1:length(yTicks)) { 64 | lines(c(1, 1.5*max(xTicks)), c(yTicks[j], yTicks[j]), col="#888888", lwd=0.5, lty=3) 65 | } 66 | lines(x, y) 67 | points(x, y, bg="#ffffff", pch=21, cex=0.8) 68 | # Labels 69 | if (length(labels) > 0) { 70 | if (log != "") { 71 | yOffset <- 0.13*y 72 | } else { 73 | yOffset <- 0.03*(max(yTicks)-min(yTicks)) 74 | } 75 | text(x, y-yOffset, labels, cex=0.5) 76 | } 77 | } 78 | connectedScatter(jamie[-(1:30), 2], jamie[-(1:30), 3], labels=jamie$year[-(1:30)], xlab="female", ylab="male") 79 | lines(c(-1,13000), c(-1,13000), col="red") 80 | connectedScatter(jamie[-(1:30), 2], jamie[-(1:30), 3], log="xy") 81 | -------------------------------------------------------------------------------- /Connected_Scatterplots/connected_scatter.R: -------------------------------------------------------------------------------- 1 | # 2 | # Load data 3 | # 4 | jamie <- read.csv('jamie-counts.csv') 5 | 6 | # 7 | # Percentages 8 | # 9 | jamie$fpct <- jamie$female / (jamie$female + jamie$male) 10 | jamie$mpct <- 1 - jamie$fpct 11 | 12 | # 13 | # Time series chart 14 | # 15 | plot(jamie$year, jamie$fpct, ylim=c(0,1)) 16 | lines(jamie$year, jamie$fpct) 17 | lines(c(1880,2012), c(0.5,0.5), col="red") 18 | 19 | # 20 | # Connected scatter plot 21 | # 22 | plot(jamie[-(1:30), 2:3]) 23 | lines(jamie[-(1:30), 2:3]) 24 | lines(c(-1,13000), c(-1,13000), col="red") 25 | text(jamie[-(1:30), 2], jamie[-(1:30), 3]-100, jamie$year[-(1:30)], cex=0.5) 26 | 27 | # 28 | # Connected scatter plot, logarithmic scale 29 | # 30 | plot(jamie[-(1:30), 2:3], log="xy") 31 | lines(jamie[-(1:30), 2:3]) 32 | lines(c(1,13000), c(1,13000), col="red") 33 | 34 | # 35 | # Same logorithmic scale, with some tweaks 36 | # 37 | plot(jamie[-(1:30), 2:3], log="xy", bty="n", las=1, type="n") 38 | 39 | # Draw grid lines 40 | xTicks <- axTicks(1) 41 | yTicks <- axTicks(2) 42 | for (i in 1:length(xTicks)) { 43 | lines(c(xTicks[i], xTicks[i]), c(1, 1.5*max(yTicks)), col="#888888", lwd=0.5, lty=3) 44 | } 45 | for (j in 1:length(yTicks)) { 46 | lines(c(1, 1.5*max(xTicks)), c(yTicks[j], yTicks[j]), col="#888888", lwd=0.5, lty=3) 47 | } 48 | 49 | # Connecting lines and points 50 | lines(jamie[-(1:30), 2:3]) 51 | points(jamie[-(1:30), 2:3], bg="#ffffff", pch=21, cex=0.8) 52 | 53 | # Labels 54 | text(jamie[-(1:30), 2], jamie[-(1:30), 3]-0.13*jamie[-(1:30), 3], jamie$year[-(1:30)], cex=0.5) 55 | 56 | 57 | 58 | # 59 | # Wrapped in a function 60 | # 61 | 62 | connectedScatter <- function(x, y, labels=c(), log="", xlab="x", ylab="y") { 63 | 64 | plot(x, y, log=log, bty="n", las=1, type="n", xlab=xlab, ylab=ylab) 65 | 66 | # Draw grid lines 67 | xTicks <- axTicks(1) 68 | yTicks <- axTicks(2) 69 | for (i in 1:length(xTicks)) { 70 | lines(c(xTicks[i], xTicks[i]), c(1, 1.5*max(yTicks)), col="#888888", lwd=0.5, lty=3) 71 | } 72 | for (j in 1:length(yTicks)) { 73 | lines(c(1, 1.5*max(xTicks)), c(yTicks[j], yTicks[j]), col="#888888", lwd=0.5, lty=3) 74 | } 75 | 76 | # Connecting lines and points 77 | lines(x, y) 78 | points(x, y, bg="#ffffff", pch=21, cex=0.8) 79 | 80 | # Labels 81 | if (length(labels) > 0) { 82 | if (log != "") { 83 | yOffset <- 0.13*y 84 | } else { 85 | yOffset <- 0.03*(max(yTicks)-min(yTicks)) 86 | } 87 | 88 | text(x, y-yOffset, labels, cex=0.5) 89 | } 90 | } 91 | 92 | 93 | # Example usage 94 | connectedScatter(jamie[-(1:30), 2], jamie[-(1:30), 3], labels=jamie$year[-(1:30)], xlab="female", ylab="male") 95 | lines(c(-1,13000), c(-1,13000), col="red") 96 | 97 | connectedScatter(jamie[-(1:30), 2], jamie[-(1:30), 3], log="xy") 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /Connected_Scatterplots/jamie-counts.csv: -------------------------------------------------------------------------------- 1 | year,female,male 2 | 1880,0,0 3 | 1881,0,0 4 | 1882,0,0 5 | 1883,0,0 6 | 1884,5,0 7 | 1885,0,0 8 | 1886,0,0 9 | 1887,5,0 10 | 1888,5,0 11 | 1889,0,0 12 | 1890,12,0 13 | 1891,11,0 14 | 1892,10,0 15 | 1893,9,0 16 | 1894,9,0 17 | 1895,10,0 18 | 1896,8,6 19 | 1897,9,5 20 | 1898,11,0 21 | 1899,14,0 22 | 1900,20,6 23 | 1901,20,0 24 | 1902,15,0 25 | 1903,9,0 26 | 1904,11,9 27 | 1905,23,9 28 | 1906,16,5 29 | 1907,15,0 30 | 1908,15,0 31 | 1909,27,11 32 | 1910,16,8 33 | 1911,15,12 34 | 1912,34,12 35 | 1913,36,20 36 | 1914,33,25 37 | 1915,59,35 38 | 1916,55,35 39 | 1917,45,28 40 | 1918,64,35 41 | 1919,73,37 42 | 1920,64,29 43 | 1921,60,37 44 | 1922,63,40 45 | 1923,71,42 46 | 1924,54,35 47 | 1925,58,35 48 | 1926,77,51 49 | 1927,56,40 50 | 1928,59,42 51 | 1929,47,41 52 | 1930,56,37 53 | 1931,68,45 54 | 1932,68,43 55 | 1933,49,44 56 | 1934,52,45 57 | 1935,49,55 58 | 1936,49,49 59 | 1937,58,34 60 | 1938,72,41 61 | 1939,62,42 62 | 1940,74,42 63 | 1941,81,43 64 | 1942,120,56 65 | 1943,154,78 66 | 1944,122,64 67 | 1945,226,80 68 | 1946,337,64 69 | 1947,327,79 70 | 1948,386,103 71 | 1949,401,98 72 | 1950,467,87 73 | 1951,546,88 74 | 1952,692,139 75 | 1953,895,204 76 | 1954,986,252 77 | 1955,1146,261 78 | 1956,1030,286 79 | 1957,1276,445 80 | 1958,1309,641 81 | 1959,1822,773 82 | 1960,2203,733 83 | 1961,2338,731 84 | 1962,2789,824 85 | 1963,2550,902 86 | 1964,2315,1111 87 | 1965,2747,944 88 | 1966,2658,962 89 | 1967,2512,1030 90 | 1968,2689,1223 91 | 1969,2901,1567 92 | 1970,3200,2642 93 | 1971,3055,3236 94 | 1972,2814,3679 95 | 1973,2953,3911 96 | 1974,3022,4090 97 | 1975,4233,4573 98 | 1976,12539,4623 99 | 1977,12901,3446 100 | 1978,10982,2866 101 | 1979,12155,2337 102 | 1980,11522,2845 103 | 1981,10978,2356 104 | 1982,11038,2091 105 | 1983,11029,1770 106 | 1984,9761,1765 107 | 1985,11036,1630 108 | 1986,9231,1467 109 | 1987,7916,1541 110 | 1988,7181,1470 111 | 1989,6848,1472 112 | 1990,6505,1317 113 | 1991,5780,1286 114 | 1992,4704,1158 115 | 1993,4254,1111 116 | 1994,3981,953 117 | 1995,3770,792 118 | 1996,3599,686 119 | 1997,3240,654 120 | 1998,3065,606 121 | 1999,2537,519 122 | 2000,2155,455 123 | 2001,1945,462 124 | 2002,1967,425 125 | 2003,1924,410 126 | 2004,1724,443 127 | 2005,1598,435 128 | 2006,1411,420 129 | 2007,1391,362 130 | 2008,1306,363 131 | 2009,1058,366 132 | 2010,839,339 133 | 2011,710,274 134 | 2012,704,250 -------------------------------------------------------------------------------- /Distributions_Plots/distributions.R: -------------------------------------------------------------------------------- 1 | # Visualizing Distributions 2 | 3 | # Load crime data 4 | crime <- read.csv("http://datasets.flowingdata.com/crimeRatesByState-formatted.csv") 5 | 6 | # Remove Washington, D.C. and national average 7 | crime.new <- crime[crime$state != "District of Columbia",] 8 | crime.new <- crime.new[crime.new$state != "United States ",] 9 | 10 | # Box plot 11 | boxplot(crime.new$robbery, horizontal=TRUE, main="Robbery Rates in US") 12 | boxplot(crime.new[,-1], horizontal=TRUE, main="Crime Rates in US") 13 | 14 | # Histogram 15 | hist(crime.new$robbery) 16 | hist(crime.new$robbery, breaks=10) 17 | 18 | par(mfrow=c(3, 3)) 19 | colnames <- dimnames(crime.new)[[2]] 20 | for (i in 2:8) { 21 | hist(crime[,i], xlim=c(0, 3500), breaks=seq(0, 3500, 100), main=colnames[i], probability=TRUE, col="gray", border="white") 22 | d <- density(crime[,i]) 23 | #lines(d, col="red") 24 | } 25 | 26 | 27 | # Density plot 28 | par(mfrow=c(3, 3)) 29 | colnames <- dimnames(crime.new)[[2]] 30 | for (i in 2:8) { 31 | d <- density(crime[,i]) 32 | plot(d, type="n", main=colnames[i]) 33 | polygon(d, col="red", border="gray") 34 | } 35 | 36 | 37 | # Density + Rug 38 | d <- density(crime$robbery) 39 | plot(d, type="n", main="robbery") 40 | polygon(d, col="lightgray", border="gray") 41 | rug(crime$robbery, col="red") 42 | 43 | # Violin plot 44 | library(vioplot) 45 | vioplot(crime.new$robbery, horizontal=TRUE, col="gray") 46 | 47 | # Bean plot 48 | library(beanplot) 49 | beanplot(crime.new[,-1]) 50 | 51 | -------------------------------------------------------------------------------- /Dot_Plots/data/ACS_13_1YR_S2002/ACS_13_1YR_S2002.csv: -------------------------------------------------------------------------------- 1 | GEO.id,GEO.id2,GEO.display-label,HC01_EST_VC01,HC01_MOE_VC01,HC02_EST_VC01,HC02_MOE_VC01,HC03_EST_VC01,HC03_MOE_VC01,HC04_EST_VC01,HC04_MOE_VC01,HC01_EST_VC04,HC01_MOE_VC04,HC02_EST_VC04,HC02_MOE_VC04,HC03_EST_VC04,HC03_MOE_VC04,HC04_EST_VC04,HC04_MOE_VC04,HC01_EST_VC05,HC01_MOE_VC05,HC02_EST_VC05,HC02_MOE_VC05,HC03_EST_VC05,HC03_MOE_VC05,HC04_EST_VC05,HC04_MOE_VC05,HC01_EST_VC06,HC01_MOE_VC06,HC02_EST_VC06,HC02_MOE_VC06,HC03_EST_VC06,HC03_MOE_VC06,HC04_EST_VC06,HC04_MOE_VC06,HC01_EST_VC07,HC01_MOE_VC07,HC02_EST_VC07,HC02_MOE_VC07,HC03_EST_VC07,HC03_MOE_VC07,HC04_EST_VC07,HC04_MOE_VC07,HC01_EST_VC08,HC01_MOE_VC08,HC02_EST_VC08,HC02_MOE_VC08,HC03_EST_VC08,HC03_MOE_VC08,HC04_EST_VC08,HC04_MOE_VC08,HC01_EST_VC09,HC01_MOE_VC09,HC02_EST_VC09,HC02_MOE_VC09,HC03_EST_VC09,HC03_MOE_VC09,HC04_EST_VC09,HC04_MOE_VC09,HC01_EST_VC10,HC01_MOE_VC10,HC02_EST_VC10,HC02_MOE_VC10,HC03_EST_VC10,HC03_MOE_VC10,HC04_EST_VC10,HC04_MOE_VC10,HC01_EST_VC12,HC01_MOE_VC12,HC02_EST_VC12,HC02_MOE_VC12,HC03_EST_VC12,HC03_MOE_VC12,HC04_EST_VC12,HC04_MOE_VC12,HC01_EST_VC13,HC01_MOE_VC13,HC02_EST_VC13,HC02_MOE_VC13,HC03_EST_VC13,HC03_MOE_VC13,HC04_EST_VC13,HC04_MOE_VC13,HC01_EST_VC16,HC01_MOE_VC16,HC02_EST_VC16,HC02_MOE_VC16,HC03_EST_VC16,HC03_MOE_VC16,HC04_EST_VC16,HC04_MOE_VC16,HC01_EST_VC17,HC01_MOE_VC17,HC02_EST_VC17,HC02_MOE_VC17,HC03_EST_VC17,HC03_MOE_VC17,HC04_EST_VC17,HC04_MOE_VC17,HC01_EST_VC18,HC01_MOE_VC18,HC02_EST_VC18,HC02_MOE_VC18,HC03_EST_VC18,HC03_MOE_VC18,HC04_EST_VC18,HC04_MOE_VC18,HC01_EST_VC19,HC01_MOE_VC19,HC02_EST_VC19,HC02_MOE_VC19,HC03_EST_VC19,HC03_MOE_VC19,HC04_EST_VC19,HC04_MOE_VC19,HC01_EST_VC20,HC01_MOE_VC20,HC02_EST_VC20,HC02_MOE_VC20,HC03_EST_VC20,HC03_MOE_VC20,HC04_EST_VC20,HC04_MOE_VC20,HC01_EST_VC21,HC01_MOE_VC21,HC02_EST_VC21,HC02_MOE_VC21,HC03_EST_VC21,HC03_MOE_VC21,HC04_EST_VC21,HC04_MOE_VC21,HC01_EST_VC23,HC01_MOE_VC23,HC02_EST_VC23,HC02_MOE_VC23,HC03_EST_VC23,HC03_MOE_VC23,HC04_EST_VC23,HC04_MOE_VC23,HC01_EST_VC25,HC01_MOE_VC25,HC02_EST_VC25,HC02_MOE_VC25,HC03_EST_VC25,HC03_MOE_VC25,HC04_EST_VC25,HC04_MOE_VC25,HC01_EST_VC26,HC01_MOE_VC26,HC02_EST_VC26,HC02_MOE_VC26,HC03_EST_VC26,HC03_MOE_VC26,HC04_EST_VC26,HC04_MOE_VC26,HC01_EST_VC27,HC01_MOE_VC27,HC02_EST_VC27,HC02_MOE_VC27,HC03_EST_VC27,HC03_MOE_VC27,HC04_EST_VC27,HC04_MOE_VC27,HC01_EST_VC28,HC01_MOE_VC28,HC02_EST_VC28,HC02_MOE_VC28,HC03_EST_VC28,HC03_MOE_VC28,HC04_EST_VC28,HC04_MOE_VC28,HC01_EST_VC29,HC01_MOE_VC29,HC02_EST_VC29,HC02_MOE_VC29,HC03_EST_VC29,HC03_MOE_VC29,HC04_EST_VC29,HC04_MOE_VC29,HC01_EST_VC30,HC01_MOE_VC30,HC02_EST_VC30,HC02_MOE_VC30,HC03_EST_VC30,HC03_MOE_VC30,HC04_EST_VC30,HC04_MOE_VC30,HC01_EST_VC31,HC01_MOE_VC31,HC02_EST_VC31,HC02_MOE_VC31,HC03_EST_VC31,HC03_MOE_VC31,HC04_EST_VC31,HC04_MOE_VC31,HC01_EST_VC32,HC01_MOE_VC32,HC02_EST_VC32,HC02_MOE_VC32,HC03_EST_VC32,HC03_MOE_VC32,HC04_EST_VC32,HC04_MOE_VC32,HC01_EST_VC33,HC01_MOE_VC33,HC02_EST_VC33,HC02_MOE_VC33,HC03_EST_VC33,HC03_MOE_VC33,HC04_EST_VC33,HC04_MOE_VC33,HC01_EST_VC34,HC01_MOE_VC34,HC02_EST_VC34,HC02_MOE_VC34,HC03_EST_VC34,HC03_MOE_VC34,HC04_EST_VC34,HC04_MOE_VC34,HC01_EST_VC35,HC01_MOE_VC35,HC02_EST_VC35,HC02_MOE_VC35,HC03_EST_VC35,HC03_MOE_VC35,HC04_EST_VC35,HC04_MOE_VC35,HC01_EST_VC36,HC01_MOE_VC36,HC02_EST_VC36,HC02_MOE_VC36,HC03_EST_VC36,HC03_MOE_VC36,HC04_EST_VC36,HC04_MOE_VC36,HC01_EST_VC37,HC01_MOE_VC37,HC02_EST_VC37,HC02_MOE_VC37,HC03_EST_VC37,HC03_MOE_VC37,HC04_EST_VC37,HC04_MOE_VC37,HC01_EST_VC38,HC01_MOE_VC38,HC02_EST_VC38,HC02_MOE_VC38,HC03_EST_VC38,HC03_MOE_VC38,HC04_EST_VC38,HC04_MOE_VC38,HC01_EST_VC39,HC01_MOE_VC39,HC02_EST_VC39,HC02_MOE_VC39,HC03_EST_VC39,HC03_MOE_VC39,HC04_EST_VC39,HC04_MOE_VC39,HC01_EST_VC40,HC01_MOE_VC40,HC02_EST_VC40,HC02_MOE_VC40,HC03_EST_VC40,HC03_MOE_VC40,HC04_EST_VC40,HC04_MOE_VC40,HC01_EST_VC41,HC01_MOE_VC41,HC02_EST_VC41,HC02_MOE_VC41,HC03_EST_VC41,HC03_MOE_VC41,HC04_EST_VC41,HC04_MOE_VC41,HC01_EST_VC42,HC01_MOE_VC42,HC02_EST_VC42,HC02_MOE_VC42,HC03_EST_VC42,HC03_MOE_VC42,HC04_EST_VC42,HC04_MOE_VC42,HC01_EST_VC43,HC01_MOE_VC43,HC02_EST_VC43,HC02_MOE_VC43,HC03_EST_VC43,HC03_MOE_VC43,HC04_EST_VC43,HC04_MOE_VC43,HC01_EST_VC44,HC01_MOE_VC44,HC02_EST_VC44,HC02_MOE_VC44,HC03_EST_VC44,HC03_MOE_VC44,HC04_EST_VC44,HC04_MOE_VC44,HC01_EST_VC45,HC01_MOE_VC45,HC02_EST_VC45,HC02_MOE_VC45,HC03_EST_VC45,HC03_MOE_VC45,HC04_EST_VC45,HC04_MOE_VC45,HC01_EST_VC46,HC01_MOE_VC46,HC02_EST_VC46,HC02_MOE_VC46,HC03_EST_VC46,HC03_MOE_VC46,HC04_EST_VC46,HC04_MOE_VC46,HC01_EST_VC47,HC01_MOE_VC47,HC02_EST_VC47,HC02_MOE_VC47,HC03_EST_VC47,HC03_MOE_VC47,HC04_EST_VC47,HC04_MOE_VC47,HC01_EST_VC50,HC01_MOE_VC50,HC02_EST_VC50,HC02_MOE_VC50,HC03_EST_VC50,HC03_MOE_VC50,HC04_EST_VC50,HC04_MOE_VC50,HC01_EST_VC51,HC01_MOE_VC51,HC02_EST_VC51,HC02_MOE_VC51,HC03_EST_VC51,HC03_MOE_VC51,HC04_EST_VC51,HC04_MOE_VC51,HC01_EST_VC52,HC01_MOE_VC52,HC02_EST_VC52,HC02_MOE_VC52,HC03_EST_VC52,HC03_MOE_VC52,HC04_EST_VC52,HC04_MOE_VC52,HC01_EST_VC53,HC01_MOE_VC53,HC02_EST_VC53,HC02_MOE_VC53,HC03_EST_VC53,HC03_MOE_VC53,HC04_EST_VC53,HC04_MOE_VC53,HC01_EST_VC54,HC01_MOE_VC54,HC02_EST_VC54,HC02_MOE_VC54,HC03_EST_VC54,HC03_MOE_VC54,HC04_EST_VC54,HC04_MOE_VC54,HC01_EST_VC55,HC01_MOE_VC55,HC02_EST_VC55,HC02_MOE_VC55,HC03_EST_VC55,HC03_MOE_VC55,HC04_EST_VC55,HC04_MOE_VC55,HC01_EST_VC56,HC01_MOE_VC56,HC02_EST_VC56,HC02_MOE_VC56,HC03_EST_VC56,HC03_MOE_VC56,HC04_EST_VC56,HC04_MOE_VC56,HC01_EST_VC57,HC01_MOE_VC57,HC02_EST_VC57,HC02_MOE_VC57,HC03_EST_VC57,HC03_MOE_VC57,HC04_EST_VC57,HC04_MOE_VC57,HC01_EST_VC58,HC01_MOE_VC58,HC02_EST_VC58,HC02_MOE_VC58,HC03_EST_VC58,HC03_MOE_VC58,HC04_EST_VC58,HC04_MOE_VC58,HC01_EST_VC59,HC01_MOE_VC59,HC02_EST_VC59,HC02_MOE_VC59,HC03_EST_VC59,HC03_MOE_VC59,HC04_EST_VC59,HC04_MOE_VC59,HC01_EST_VC60,HC01_MOE_VC60,HC02_EST_VC60,HC02_MOE_VC60,HC03_EST_VC60,HC03_MOE_VC60,HC04_EST_VC60,HC04_MOE_VC60,HC01_EST_VC61,HC01_MOE_VC61,HC02_EST_VC61,HC02_MOE_VC61,HC03_EST_VC61,HC03_MOE_VC61,HC04_EST_VC61,HC04_MOE_VC61,HC01_EST_VC62,HC01_MOE_VC62,HC02_EST_VC62,HC02_MOE_VC62,HC03_EST_VC62,HC03_MOE_VC62,HC04_EST_VC62,HC04_MOE_VC62,HC01_EST_VC63,HC01_MOE_VC63,HC02_EST_VC63,HC02_MOE_VC63,HC03_EST_VC63,HC03_MOE_VC63,HC04_EST_VC63,HC04_MOE_VC63,HC01_EST_VC64,HC01_MOE_VC64,HC02_EST_VC64,HC02_MOE_VC64,HC03_EST_VC64,HC03_MOE_VC64,HC04_EST_VC64,HC04_MOE_VC64,HC01_EST_VC65,HC01_MOE_VC65,HC02_EST_VC65,HC02_MOE_VC65,HC03_EST_VC65,HC03_MOE_VC65,HC04_EST_VC65,HC04_MOE_VC65,HC01_EST_VC66,HC01_MOE_VC66,HC02_EST_VC66,HC02_MOE_VC66,HC03_EST_VC66,HC03_MOE_VC66,HC04_EST_VC66,HC04_MOE_VC66,HC01_EST_VC67,HC01_MOE_VC67,HC02_EST_VC67,HC02_MOE_VC67,HC03_EST_VC67,HC03_MOE_VC67,HC04_EST_VC67,HC04_MOE_VC67,HC01_EST_VC68,HC01_MOE_VC68,HC02_EST_VC68,HC02_MOE_VC68,HC03_EST_VC68,HC03_MOE_VC68,HC04_EST_VC68,HC04_MOE_VC68,HC01_EST_VC69,HC01_MOE_VC69,HC02_EST_VC69,HC02_MOE_VC69,HC03_EST_VC69,HC03_MOE_VC69,HC04_EST_VC69,HC04_MOE_VC69,HC01_EST_VC72,HC01_MOE_VC72,HC02_EST_VC72,HC02_MOE_VC72,HC03_EST_VC72,HC03_MOE_VC72,HC04_EST_VC72,HC04_MOE_VC72,HC01_EST_VC73,HC01_MOE_VC73,HC02_EST_VC73,HC02_MOE_VC73,HC03_EST_VC73,HC03_MOE_VC73,HC04_EST_VC73,HC04_MOE_VC73,HC01_EST_VC74,HC01_MOE_VC74,HC02_EST_VC74,HC02_MOE_VC74,HC03_EST_VC74,HC03_MOE_VC74,HC04_EST_VC74,HC04_MOE_VC74,HC01_EST_VC75,HC01_MOE_VC75,HC02_EST_VC75,HC02_MOE_VC75,HC03_EST_VC75,HC03_MOE_VC75,HC04_EST_VC75,HC04_MOE_VC75,HC01_EST_VC76,HC01_MOE_VC76,HC02_EST_VC76,HC02_MOE_VC76,HC03_EST_VC76,HC03_MOE_VC76,HC04_EST_VC76,HC04_MOE_VC76,HC01_EST_VC77,HC01_MOE_VC77,HC02_EST_VC77,HC02_MOE_VC77,HC03_EST_VC77,HC03_MOE_VC77,HC04_EST_VC77,HC04_MOE_VC77,HC01_EST_VC78,HC01_MOE_VC78,HC02_EST_VC78,HC02_MOE_VC78,HC03_EST_VC78,HC03_MOE_VC78,HC04_EST_VC78,HC04_MOE_VC78,HC01_EST_VC81,HC01_MOE_VC81,HC02_EST_VC81,HC02_MOE_VC81,HC03_EST_VC81,HC03_MOE_VC81,HC04_EST_VC81,HC04_MOE_VC81,HC01_EST_VC82,HC01_MOE_VC82,HC02_EST_VC82,HC02_MOE_VC82,HC03_EST_VC82,HC03_MOE_VC82,HC04_EST_VC82,HC04_MOE_VC82,HC01_EST_VC83,HC01_MOE_VC83,HC02_EST_VC83,HC02_MOE_VC83,HC03_EST_VC83,HC03_MOE_VC83,HC04_EST_VC83,HC04_MOE_VC83,HC01_EST_VC84,HC01_MOE_VC84,HC02_EST_VC84,HC02_MOE_VC84,HC03_EST_VC84,HC03_MOE_VC84,HC04_EST_VC84,HC04_MOE_VC84,HC01_EST_VC85,HC01_MOE_VC85,HC02_EST_VC85,HC02_MOE_VC85,HC03_EST_VC85,HC03_MOE_VC85,HC04_EST_VC85,HC04_MOE_VC85,HC01_EST_VC86,HC01_MOE_VC86,HC02_EST_VC86,HC02_MOE_VC86,HC03_EST_VC86,HC03_MOE_VC86,HC04_EST_VC86,HC04_MOE_VC86,HC01_EST_VC87,HC01_MOE_VC87,HC02_EST_VC87,HC02_MOE_VC87,HC03_EST_VC87,HC03_MOE_VC87,HC04_EST_VC87,HC04_MOE_VC87 2 | 0100000US,,United States,,,48099,156,38097,137,79.2,0.4,,,50776,59,39946,137,78.7,0.3,,,37290,168,33780,337,90.6,1.0,,,36351,598,31063,388,85.5,1.8,,,59706,972,47325,361,79.3,1.4,,,40817,935,34330,2297,84.1,5.4,,,30176,169,26305,228,87.2,0.8,,,42019,318,36995,350,88.0,1.0,,,31596,117,28526,262,90.3,0.8,,,52452,59,41010,61,78.2,0.1,35597,41,41385,52,30195,39,73.0,0.1,20149,65,23059,137,15308,89,66.4,0.5,27350,54,32212,66,21968,58,68.2,0.2,32387,45,40667,92,27436,63,67.5,0.2,50050,82,60909,121,41110,92,67.5,0.2,65565,180,81789,223,54916,325,67.1,0.5,42498,122,48520,158,38233,136,78.8,0.4,70783,166,79836,643,59964,475,75.1,0.9,60692,188,70670,382,52958,549,74.9,0.9,76739,318,80509,302,69795,1069,86.7,1.4,76706,342,79244,845,64961,1491,82.0,1.9,62089,324,66913,747,57617,1206,86.1,2.1,42023,216,43927,958,41485,247,94.4,2.0,83735,1918,116689,3545,61432,675,52.6,1.7,47331,168,55349,334,44667,327,80.7,0.7,50909,260,52617,1052,47086,580,89.5,1.9,61014,128,80723,690,56710,228,70.3,0.7,27158,149,30838,367,26743,160,86.7,1.2,49316,674,51159,286,40760,396,79.7,0.9,21343,97,22483,179,20049,147,89.2,0.9,25267,177,27873,407,20844,146,74.8,1.1,24051,258,30217,349,22294,149,73.8,0.9,41300,122,50259,154,31747,149,63.2,0.3,35120,87,38713,515,33637,161,86.9,1.1,25086,389,26271,366,18998,690,72.3,2.6,40003,298,40078,161,33236,2534,82.9,6.4,43450,531,43781,566,40347,924,92.2,2.6,35478,124,39170,326,26544,136,67.8,0.7,40594,144,41222,146,30304,506,73.5,1.3,28861,306,30415,163,23419,441,77.0,1.6,30979,250,31794,249,23017,1068,72.4,3.3,65421,620,66704,665,55303,2071,82.9,3.3,41301,114,41432,127,39933,838,96.4,2.1,46350,155,50446,131,36948,185,73.2,0.4,46540,296,49458,636,40858,366,82.6,1.2,32000,80,36545,155,28353,270,77.6,0.8,46767,218,48595,496,41301,300,85.0,1.1,65430,502,69394,1143,52337,1006,75.4,1.9,56767,488,62310,419,48972,896,78.6,1.5,53388,549,76535,555,44088,464,57.6,0.7,42433,376,46842,471,40284,334,86.0,1.0,70092,323,81838,268,52621,602,64.3,0.7,68877,3592,90866,4322,52698,2812,58.0,4.1,31506,145,32144,213,30407,201,94.6,0.9,46786,147,51566,175,44643,288,86.6,0.6,40819,101,52422,321,37410,112,71.4,0.5,35307,307,36882,394,31915,335,86.5,1.3,23933,208,25900,221,21737,142,83.9,0.9,32387,141,37089,288,28253,465,76.2,1.3,53849,350,60954,216,46957,260,77.0,0.5,41185,51,46304,102,35695,72,77.1,0.2,56873,737,61601,264,43322,1870,70.3,3.0,46235,192,51389,231,42713,408,83.1,0.8,47885,260,52008,163,44045,357,84.7,0.7,47044,162,52002,195,43258,366,83.2,0.8,61336,225,64688,760,56753,366,87.7,1.2,32492,526,37653,894,25596,332,68.0,1.8,20.1,,,,,,,,1.6,,,,,,,,2.1,,,,,,,,7.1,,,,,,,,10.1,,,,,,,,9.6,,,,,,,,8.8,,,,,,, 3 | -------------------------------------------------------------------------------- /Dot_Plots/data/ACS_13_1YR_S2002/ACS_13_1YR_S2002.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plissonf/FlowingData/7a7115de92496cd422714dc353aa0c8a0f76c9f4/Dot_Plots/data/ACS_13_1YR_S2002/ACS_13_1YR_S2002.txt -------------------------------------------------------------------------------- /Dot_Plots/data/ACS_13_1YR_S2002/aff_download_readme.txt: -------------------------------------------------------------------------------- 1 | 2 | This zip file contains a number of documents containing materials related to the table which you have downloaded. These include: 3 | 1. aff_download_readme.txt (this file) 4 | 2. .csv (data file) 5 | 3. _ann.csv (annotation file, if applicable) 6 | 4. .txt (notes file) 7 | 5. _metadata.csv (metadata file) 8 | 9 | Naming convention: 10 | 11 | The table file name is based on the Table Id. 12 | For Geographic Comparison Tables (GCT) and Geographic Ranking Tables (GRT), the table file name is based on Table ID and Stub. 13 | 14 | 15 | Document descriptions: 16 | 17 | Data file: 18 | file name: .csv 19 | Includes the tabular data for the table. 20 | 21 | Annotation file: 22 | file name: _ann.csv 23 | This file contains cell annotations, which could be simple jam values, flag symbols, or codes of more complex cell annotations that replace the values in the data file. This file has a parallel structure to the data file, but it includes only those lines that correspond to the lines from the data file that have annotations. If there are no lines to be included in the annotation file, then the whole annotation file is omitted. A cell annotation starts with '$' or 'ECONF$', and the string that follows the '$' char is the jamming string or flag symbol. For example, '$1000+' is a simple cell annotation that would replace the content of the cell with the string '1000+'. A cell annotation that does not start with '$', such as 'ECONF$', is a code that is described in the notes file (see below). 24 | 25 | Notes file: 26 | file name: .txt 27 | This file contains the head notes, footnotes and the description of the cell annotations occurring in the data file (simple jamming cell annotations are excluded). 28 | 29 | Metadata file: 30 | file name: _metadata.csv 31 | This file contains the header information (transposed), without the data associated with the table. -------------------------------------------------------------------------------- /Dot_Plots/data/ACS_13_1YR_S2401-by-occ.csv: -------------------------------------------------------------------------------- 1 | occupation,level,total_est,total_moe,male_pct,male_moe,female_pct,female_moe,med_salary,med_salary_moe,med_salary_male,med_salary_male_moe,med_salary_female,med_salary_female_moe Civilian employed population 16 years and over,0,145128676,124890,0.53,0.1,0.48,0.1,32387,32,39530,151,27627,92 "Management, business, science, and arts occupations",0,52753573,134159,0.48,0.1,0.52,0.1,52478,54,65997,129,45722,94 "Management, business, and financial occupations",1,21201006,85392,0.56,0.2,0.44,0.2,61059,111,71340,177,51203,129 Management occupations,2,14257292,63419,0.61,0.2,0.39,0.2,64994,273,74433,567,52491,377 Business and financial operations occupations,2,6943714,47408,0.45,0.3,0.55,0.3,54454,446,64574,837,49071,445 "Computer, engineering, and science occupations",1,7782601,50809,0.74,0.2,0.26,0.2,70129,200,73511,544,58110,888 Computer and mathematical occupations,2,3875030,33017,0.74,0.3,0.26,0.3,71730,259,75493,416,62745,962 Architecture and engineering occupations,2,2658394,31467,0.85,0.3,0.15,0.3,72208,268,75551,322,57996,1823 "Life, physical, and social science occupations",2,1249177,17685,0.54,0.7,0.47,0.7,53844,962,60372,670,50236,569 "Education, legal, community service, arts, and media occupations",1,15648385,68432,0.36,0.1,0.64,0.1,40384,90,47513,309,36490,126 Community and social services occupations,2,2369635,26111,0.37,0.5,0.63,0.5,37573,376,39841,662,37003,212 Legal occupations,2,1681294,24908,0.49,0.6,0.51,0.6,72063,661,101879,443,53664,1432 "Education, training, and library occupations",2,8791356,52661,0.27,0.2,0.73,0.2,38195,302,46785,298,35295,204 "Arts, design, entertainment, sports, and media occupations",2,2806100,25703,0.54,0.5,0.46,0.5,36231,284,41226,334,30875,363 Healthcare practitioner and technical occupations,1,8121581,44992,0.25,0.2,0.75,0.2,52425,144,72979,1552,50275,148 Health diagnosing and treating practitioners and other technical occupations,2,5626924,38349,0.27,0.3,0.73,0.3,62650,461,100320,368,58749,621 Health technologists and technicians,2,2494657,25558,0.22,0.4,0.78,0.4,35646,220,40620,421,34240,547 Service occupations,0,26654335,95448,0.44,0.2,0.56,0.2,17425,61,21446,85,15391,62 Healthcare support occupations,1,3752165,37363,0.13,0.3,0.87,0.3,21942,108,25193,481,21661,119 Protective service occupations,1,3190761,28192,0.78,0.4,0.22,0.4,40702,223,43238,796,31071,430 "Fire fighting and prevention, and other protective service workers including supervisors",2,1796111,21347,0.76,0.6,0.24,0.6,28697,627,31353,326,20814,466 Law enforcement workers including supervisors,2,1394650,19300,0.80,0.6,0.20,0.6,53867,960,56758,557,44899,1269 Food preparation and serving related occupations,1,8464136,60482,0.46,0.3,0.54,0.3,12858,117,15228,155,11768,57 Building and grounds cleaning and maintenance occupations,1,5853358,46469,0.60,0.4,0.40,0.4,18050,172,21528,168,14096,183 Personal care and service occupations,1,5393915,38169,0.23,0.3,0.77,0.3,15200,115,18945,524,14211,178 Sales and office occupations,0,35109334,92907,0.38,0.1,0.62,0.1,27412,58,33653,351,25266,68 Sales and related occupations,1,15688353,68562,0.50,0.2,0.50,0.2,26075,117,38567,462,17415,102 Office and administrative support occupations,1,19420981,66607,0.28,0.2,0.72,0.2,28482,128,30122,151,27981,130 "Natural resources, construction, and maintenance occupations",0,12924043,62907,0.95,0.1,0.05,0.1,33084,320,34392,338,20966,356 "Farming, fishing, and forestry occupations",1,1041894,23115,0.79,0.7,0.21,0.7,19166,453,21144,294,13435,490 Construction and extraction occupations,1,7235513,45686,0.97,0.1,0.03,0.1,31857,101,31966,107,25081,879 "Installation, maintenance, and repair occupations",1,4646636,33956,0.96,0.2,0.04,0.2,40410,137,40551,141,33451,2637 "Production, transportation, and material moving occupations",0,17687391,70493,0.78,0.2,0.22,0.2,29425,163,31660,85,21307,95 Production occupations,1,8712986,47595,0.72,0.2,0.28,0.2,30936,88,35364,144,22245,129 Transportation occupations,1,5229882,39117,0.87,0.3,0.13,0.3,31897,122,34648,486,21147,268 Material moving occupations,1,3744523,36466,0.80,0.3,0.20,0.3,21626,127,22837,311,17329,244 -------------------------------------------------------------------------------- /Dot_Plots/data/ACS_13_1YR_S2401-by-occ.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plissonf/FlowingData/7a7115de92496cd422714dc353aa0c8a0f76c9f4/Dot_Plots/data/ACS_13_1YR_S2401-by-occ.xlsx -------------------------------------------------------------------------------- /Dot_Plots/data/ACS_13_1YR_S2401/ACS_13_1YR_S2401.csv: -------------------------------------------------------------------------------- 1 | GEO.id,GEO.id2,GEO.display-label,HC01_EST_VC01,HC01_MOE_VC01,HC02_EST_VC01,HC02_MOE_VC01,HC03_EST_VC01,HC03_MOE_VC01,HC04_EST_VC01,HC04_MOE_VC01,HC05_EST_VC01,HC05_MOE_VC01,HC06_EST_VC01,HC06_MOE_VC01,HC01_EST_VC02,HC01_MOE_VC02,HC02_EST_VC02,HC02_MOE_VC02,HC03_EST_VC02,HC03_MOE_VC02,HC04_EST_VC02,HC04_MOE_VC02,HC05_EST_VC02,HC05_MOE_VC02,HC06_EST_VC02,HC06_MOE_VC02,HC01_EST_VC03,HC01_MOE_VC03,HC02_EST_VC03,HC02_MOE_VC03,HC03_EST_VC03,HC03_MOE_VC03,HC04_EST_VC03,HC04_MOE_VC03,HC05_EST_VC03,HC05_MOE_VC03,HC06_EST_VC03,HC06_MOE_VC03,HC01_EST_VC04,HC01_MOE_VC04,HC02_EST_VC04,HC02_MOE_VC04,HC03_EST_VC04,HC03_MOE_VC04,HC04_EST_VC04,HC04_MOE_VC04,HC05_EST_VC04,HC05_MOE_VC04,HC06_EST_VC04,HC06_MOE_VC04,HC01_EST_VC05,HC01_MOE_VC05,HC02_EST_VC05,HC02_MOE_VC05,HC03_EST_VC05,HC03_MOE_VC05,HC04_EST_VC05,HC04_MOE_VC05,HC05_EST_VC05,HC05_MOE_VC05,HC06_EST_VC05,HC06_MOE_VC05,HC01_EST_VC06,HC01_MOE_VC06,HC02_EST_VC06,HC02_MOE_VC06,HC03_EST_VC06,HC03_MOE_VC06,HC04_EST_VC06,HC04_MOE_VC06,HC05_EST_VC06,HC05_MOE_VC06,HC06_EST_VC06,HC06_MOE_VC06,HC01_EST_VC07,HC01_MOE_VC07,HC02_EST_VC07,HC02_MOE_VC07,HC03_EST_VC07,HC03_MOE_VC07,HC04_EST_VC07,HC04_MOE_VC07,HC05_EST_VC07,HC05_MOE_VC07,HC06_EST_VC07,HC06_MOE_VC07,HC01_EST_VC08,HC01_MOE_VC08,HC02_EST_VC08,HC02_MOE_VC08,HC03_EST_VC08,HC03_MOE_VC08,HC04_EST_VC08,HC04_MOE_VC08,HC05_EST_VC08,HC05_MOE_VC08,HC06_EST_VC08,HC06_MOE_VC08,HC01_EST_VC09,HC01_MOE_VC09,HC02_EST_VC09,HC02_MOE_VC09,HC03_EST_VC09,HC03_MOE_VC09,HC04_EST_VC09,HC04_MOE_VC09,HC05_EST_VC09,HC05_MOE_VC09,HC06_EST_VC09,HC06_MOE_VC09,HC01_EST_VC10,HC01_MOE_VC10,HC02_EST_VC10,HC02_MOE_VC10,HC03_EST_VC10,HC03_MOE_VC10,HC04_EST_VC10,HC04_MOE_VC10,HC05_EST_VC10,HC05_MOE_VC10,HC06_EST_VC10,HC06_MOE_VC10,HC01_EST_VC11,HC01_MOE_VC11,HC02_EST_VC11,HC02_MOE_VC11,HC03_EST_VC11,HC03_MOE_VC11,HC04_EST_VC11,HC04_MOE_VC11,HC05_EST_VC11,HC05_MOE_VC11,HC06_EST_VC11,HC06_MOE_VC11,HC01_EST_VC12,HC01_MOE_VC12,HC02_EST_VC12,HC02_MOE_VC12,HC03_EST_VC12,HC03_MOE_VC12,HC04_EST_VC12,HC04_MOE_VC12,HC05_EST_VC12,HC05_MOE_VC12,HC06_EST_VC12,HC06_MOE_VC12,HC01_EST_VC13,HC01_MOE_VC13,HC02_EST_VC13,HC02_MOE_VC13,HC03_EST_VC13,HC03_MOE_VC13,HC04_EST_VC13,HC04_MOE_VC13,HC05_EST_VC13,HC05_MOE_VC13,HC06_EST_VC13,HC06_MOE_VC13,HC01_EST_VC14,HC01_MOE_VC14,HC02_EST_VC14,HC02_MOE_VC14,HC03_EST_VC14,HC03_MOE_VC14,HC04_EST_VC14,HC04_MOE_VC14,HC05_EST_VC14,HC05_MOE_VC14,HC06_EST_VC14,HC06_MOE_VC14,HC01_EST_VC15,HC01_MOE_VC15,HC02_EST_VC15,HC02_MOE_VC15,HC03_EST_VC15,HC03_MOE_VC15,HC04_EST_VC15,HC04_MOE_VC15,HC05_EST_VC15,HC05_MOE_VC15,HC06_EST_VC15,HC06_MOE_VC15,HC01_EST_VC16,HC01_MOE_VC16,HC02_EST_VC16,HC02_MOE_VC16,HC03_EST_VC16,HC03_MOE_VC16,HC04_EST_VC16,HC04_MOE_VC16,HC05_EST_VC16,HC05_MOE_VC16,HC06_EST_VC16,HC06_MOE_VC16,HC01_EST_VC17,HC01_MOE_VC17,HC02_EST_VC17,HC02_MOE_VC17,HC03_EST_VC17,HC03_MOE_VC17,HC04_EST_VC17,HC04_MOE_VC17,HC05_EST_VC17,HC05_MOE_VC17,HC06_EST_VC17,HC06_MOE_VC17,HC01_EST_VC18,HC01_MOE_VC18,HC02_EST_VC18,HC02_MOE_VC18,HC03_EST_VC18,HC03_MOE_VC18,HC04_EST_VC18,HC04_MOE_VC18,HC05_EST_VC18,HC05_MOE_VC18,HC06_EST_VC18,HC06_MOE_VC18,HC01_EST_VC19,HC01_MOE_VC19,HC02_EST_VC19,HC02_MOE_VC19,HC03_EST_VC19,HC03_MOE_VC19,HC04_EST_VC19,HC04_MOE_VC19,HC05_EST_VC19,HC05_MOE_VC19,HC06_EST_VC19,HC06_MOE_VC19,HC01_EST_VC20,HC01_MOE_VC20,HC02_EST_VC20,HC02_MOE_VC20,HC03_EST_VC20,HC03_MOE_VC20,HC04_EST_VC20,HC04_MOE_VC20,HC05_EST_VC20,HC05_MOE_VC20,HC06_EST_VC20,HC06_MOE_VC20,HC01_EST_VC21,HC01_MOE_VC21,HC02_EST_VC21,HC02_MOE_VC21,HC03_EST_VC21,HC03_MOE_VC21,HC04_EST_VC21,HC04_MOE_VC21,HC05_EST_VC21,HC05_MOE_VC21,HC06_EST_VC21,HC06_MOE_VC21,HC01_EST_VC22,HC01_MOE_VC22,HC02_EST_VC22,HC02_MOE_VC22,HC03_EST_VC22,HC03_MOE_VC22,HC04_EST_VC22,HC04_MOE_VC22,HC05_EST_VC22,HC05_MOE_VC22,HC06_EST_VC22,HC06_MOE_VC22,HC01_EST_VC23,HC01_MOE_VC23,HC02_EST_VC23,HC02_MOE_VC23,HC03_EST_VC23,HC03_MOE_VC23,HC04_EST_VC23,HC04_MOE_VC23,HC05_EST_VC23,HC05_MOE_VC23,HC06_EST_VC23,HC06_MOE_VC23,HC01_EST_VC24,HC01_MOE_VC24,HC02_EST_VC24,HC02_MOE_VC24,HC03_EST_VC24,HC03_MOE_VC24,HC04_EST_VC24,HC04_MOE_VC24,HC05_EST_VC24,HC05_MOE_VC24,HC06_EST_VC24,HC06_MOE_VC24,HC01_EST_VC25,HC01_MOE_VC25,HC02_EST_VC25,HC02_MOE_VC25,HC03_EST_VC25,HC03_MOE_VC25,HC04_EST_VC25,HC04_MOE_VC25,HC05_EST_VC25,HC05_MOE_VC25,HC06_EST_VC25,HC06_MOE_VC25,HC01_EST_VC26,HC01_MOE_VC26,HC02_EST_VC26,HC02_MOE_VC26,HC03_EST_VC26,HC03_MOE_VC26,HC04_EST_VC26,HC04_MOE_VC26,HC05_EST_VC26,HC05_MOE_VC26,HC06_EST_VC26,HC06_MOE_VC26,HC01_EST_VC27,HC01_MOE_VC27,HC02_EST_VC27,HC02_MOE_VC27,HC03_EST_VC27,HC03_MOE_VC27,HC04_EST_VC27,HC04_MOE_VC27,HC05_EST_VC27,HC05_MOE_VC27,HC06_EST_VC27,HC06_MOE_VC27,HC01_EST_VC28,HC01_MOE_VC28,HC02_EST_VC28,HC02_MOE_VC28,HC03_EST_VC28,HC03_MOE_VC28,HC04_EST_VC28,HC04_MOE_VC28,HC05_EST_VC28,HC05_MOE_VC28,HC06_EST_VC28,HC06_MOE_VC28,HC01_EST_VC29,HC01_MOE_VC29,HC02_EST_VC29,HC02_MOE_VC29,HC03_EST_VC29,HC03_MOE_VC29,HC04_EST_VC29,HC04_MOE_VC29,HC05_EST_VC29,HC05_MOE_VC29,HC06_EST_VC29,HC06_MOE_VC29,HC01_EST_VC30,HC01_MOE_VC30,HC02_EST_VC30,HC02_MOE_VC30,HC03_EST_VC30,HC03_MOE_VC30,HC04_EST_VC30,HC04_MOE_VC30,HC05_EST_VC30,HC05_MOE_VC30,HC06_EST_VC30,HC06_MOE_VC30,HC01_EST_VC31,HC01_MOE_VC31,HC02_EST_VC31,HC02_MOE_VC31,HC03_EST_VC31,HC03_MOE_VC31,HC04_EST_VC31,HC04_MOE_VC31,HC05_EST_VC31,HC05_MOE_VC31,HC06_EST_VC31,HC06_MOE_VC31,HC01_EST_VC32,HC01_MOE_VC32,HC02_EST_VC32,HC02_MOE_VC32,HC03_EST_VC32,HC03_MOE_VC32,HC04_EST_VC32,HC04_MOE_VC32,HC05_EST_VC32,HC05_MOE_VC32,HC06_EST_VC32,HC06_MOE_VC32,HC01_EST_VC33,HC01_MOE_VC33,HC02_EST_VC33,HC02_MOE_VC33,HC03_EST_VC33,HC03_MOE_VC33,HC04_EST_VC33,HC04_MOE_VC33,HC05_EST_VC33,HC05_MOE_VC33,HC06_EST_VC33,HC06_MOE_VC33,HC01_EST_VC34,HC01_MOE_VC34,HC02_EST_VC34,HC02_MOE_VC34,HC03_EST_VC34,HC03_MOE_VC34,HC04_EST_VC34,HC04_MOE_VC34,HC05_EST_VC34,HC05_MOE_VC34,HC06_EST_VC34,HC06_MOE_VC34,HC01_EST_VC35,HC01_MOE_VC35,HC02_EST_VC35,HC02_MOE_VC35,HC03_EST_VC35,HC03_MOE_VC35,HC04_EST_VC35,HC04_MOE_VC35,HC05_EST_VC35,HC05_MOE_VC35,HC06_EST_VC35,HC06_MOE_VC35,HC01_EST_VC36,HC01_MOE_VC36,HC02_EST_VC36,HC02_MOE_VC36,HC03_EST_VC36,HC03_MOE_VC36,HC04_EST_VC36,HC04_MOE_VC36,HC05_EST_VC36,HC05_MOE_VC36,HC06_EST_VC36,HC06_MOE_VC36,HC01_EST_VC39,HC01_MOE_VC39,HC02_EST_VC39,HC02_MOE_VC39,HC03_EST_VC39,HC03_MOE_VC39,HC04_EST_VC39,HC04_MOE_VC39,HC05_EST_VC39,HC05_MOE_VC39,HC06_EST_VC39,HC06_MOE_VC39 2 | 0100000US,,United States,145128676,124890,52.5,0.1,47.5,0.1,32387,32,39530,151,27627,92,52753573,134159,47.8,0.1,52.2,0.1,52478,54,65997,129,45722,94,21201006,85392,55.6,0.2,44.4,0.2,61059,111,71340,177,51203,129,14257292,63419,60.8,0.2,39.2,0.2,64994,273,74433,567,52491,377,6943714,47408,44.9,0.3,55.1,0.3,54454,446,64574,837,49071,445,7782601,50809,74.2,0.2,25.8,0.2,70129,200,73511,544,58110,888,3875030,33017,73.7,0.3,26.3,0.3,71730,259,75493,416,62745,962,2658394,31467,84.8,0.3,15.2,0.3,72208,268,75551,322,57996,1823,1249177,17685,53.5,0.7,46.5,0.7,53844,962,60372,670,50236,569,15648385,68432,35.8,0.1,64.2,0.1,40384,90,47513,309,36490,126,2369635,26111,36.9,0.5,63.1,0.5,37573,376,39841,662,37003,212,1681294,24908,48.6,0.6,51.4,0.6,72063,661,101879,443,53664,1432,8791356,52661,27.2,0.2,72.8,0.2,38195,302,46785,298,35295,204,2806100,25703,54.3,0.5,45.7,0.5,36231,284,41226,334,30875,363,8121581,44992,25.4,0.2,74.6,0.2,52425,144,72979,1552,50275,148,5626924,38349,26.9,0.3,73.1,0.3,62650,461,100320,368,58749,621,2494657,25558,22.0,0.4,78.0,0.4,35646,220,40620,421,34240,547,26654335,95448,43.6,0.2,56.4,0.2,17425,61,21446,85,15391,62,3752165,37363,13.4,0.3,86.6,0.3,21942,108,25193,481,21661,119,3190761,28192,77.6,0.4,22.4,0.4,40702,223,43238,796,31071,430,1796111,21347,75.7,0.6,24.3,0.6,28697,627,31353,326,20814,466,1394650,19300,80.0,0.6,20.0,0.6,53867,960,56758,557,44899,1269,8464136,60482,45.8,0.3,54.2,0.3,12858,117,15228,155,11768,57,5853358,46469,60.4,0.4,39.6,0.4,18050,172,21528,168,14096,183,5393915,38169,22.8,0.3,77.2,0.3,15200,115,18945,524,14211,178,35109334,92907,37.6,0.1,62.4,0.1,27412,58,33653,351,25266,68,15688353,68562,50.0,0.2,50.0,0.2,26075,117,38567,462,17415,102,19420981,66607,27.6,0.2,72.4,0.2,28482,128,30122,151,27981,130,12924043,62907,95.4,0.1,4.6,0.1,33084,320,34392,338,20966,356,1041894,23115,78.8,0.7,21.2,0.7,19166,453,21144,294,13435,490,7235513,45686,97.3,0.1,2.7,0.1,31857,101,31966,107,25081,879,4646636,33956,96.0,0.2,4.0,0.2,40410,137,40551,141,33451,2637,17687391,70493,77.9,0.2,22.1,0.2,29425,163,31660,85,21307,95,8712986,47595,71.7,0.2,28.3,0.2,30936,88,35364,144,22245,129,5229882,39117,86.7,0.3,13.3,0.3,31897,122,34648,486,21147,268,3744523,36466,79.8,0.3,20.2,0.3,21626,127,22837,311,17329,244,10.5,,,,,,,,,,, 3 | -------------------------------------------------------------------------------- /Dot_Plots/data/ACS_13_1YR_S2401/ACS_13_1YR_S2401.txt: -------------------------------------------------------------------------------- 1 | S2401 2 | OCCUPATION BY SEX AND MEDIAN EARNINGS IN THE PAST 12 MONTHS (IN 2013 INFLATION-ADJUSTED DOLLARS) FOR THE CIVILIAN EMPLOYED POPULATION 16 YEARS AND OVER 3 | 4 | Although the American Community Survey (ACS) produces population, demographic and housing unit estimates, it is the Census Bureau's Population Estimates Program that produces and disseminates the official estimates of the population for the nation, states, counties, cities and towns and estimates of housing units for states and counties. 5 | 6 | 7 | Supporting documentation on code lists, subject definitions, data accuracy, and statistical testing can be found on the American Community Survey website in the Data and Documentation section. 8 | 9 | Sample size and data quality measures (including coverage rates, allocation rates, and response rates) can be found on the American Community Survey website in the Methodology section. 10 | 11 | 12 | Source: U.S. Census Bureau, 2013 American Community Survey 13 | 14 | 15 | Explanation of Symbols:An '**' entry in the margin of error column indicates that either no sample observations or too few sample observations were available to compute a standard error and thus the margin of error. A statistical test is not appropriate. 16 | An '-' entry in the estimate column indicates that either no sample observations or too few sample observations were available to compute an estimate, or a ratio of medians cannot be calculated because one or both of the median estimates falls in the lowest interval or upper interval of an open-ended distribution. 17 | An '-' following a median estimate means the median falls in the lowest interval of an open-ended distribution. 18 | An '+' following a median estimate means the median falls in the upper interval of an open-ended distribution. 19 | An '***' entry in the margin of error column indicates that the median falls in the lowest interval or upper interval of an open-ended distribution. A statistical test is not appropriate. 20 | An '*****' entry in the margin of error column indicates that the estimate is controlled. A statistical test for sampling variability is not appropriate. 21 | An 'N' entry in the estimate and margin of error columns indicates that data for this geographic area cannot be displayed because the number of sample cases is too small. 22 | An '(X)' means that the estimate is not applicable or not available. 23 | 24 | 25 | Data are based on a sample and are subject to sampling variability. The degree of uncertainty for an estimate arising from sampling variability is represented through the use of a margin of error. The value shown here is the 90 percent margin of error. The margin of error can be interpreted roughly as providing a 90 percent probability that the interval defined by the estimate minus the margin of error and the estimate plus the margin of error (the lower and upper confidence bounds) contains the true value. In addition to sampling variability, the ACS estimates are subject to nonsampling error (for a discussion of nonsampling variability, see Accuracy of the Data). The effect of nonsampling error is not represented in these tables. 26 | 27 | 28 | In data year 2013, there were a series of changes to data collection operations that could have affected some estimates. These changes include the addition of Internet as a mode of data collection, the end of the content portion of Failed Edit Follow-Up interviewing, and the loss of one monthly panel due to the Federal Government shut down in October 2013. For more information, see: User Notes 29 | 30 | 31 | Occupation codes are 4-digit codes and are based on Standard Occupational Classification 2010. 32 | 33 | 34 | While the 2013 American Community Survey (ACS) data generally reflect the February 2013 Office of Management and Budget (OMB) definitions of metropolitan and micropolitan statistical areas; in certain instances the names, codes, and boundaries of the principal cities shown in ACS tables may differ from the OMB definitions due to differences in the effective dates of the geographic entities. 35 | 36 | 37 | Estimates of urban and rural population, housing units, and characteristics reflect boundaries of urban areas defined based on Census 2010 data. As a result, data for urban and rural areas from the ACS do not necessarily reflect the results of ongoing urbanization. 38 | 39 | 40 | -------------------------------------------------------------------------------- /Dot_Plots/data/ACS_13_1YR_S2401/aff_download_readme.txt: -------------------------------------------------------------------------------- 1 | 2 | This zip file contains a number of documents containing materials related to the table which you have downloaded. These include: 3 | 1. aff_download_readme.txt (this file) 4 | 2. .csv (data file) 5 | 3. _ann.csv (annotation file, if applicable) 6 | 4. .txt (notes file) 7 | 5. _metadata.csv (metadata file) 8 | 9 | Naming convention: 10 | 11 | The table file name is based on the Table Id. 12 | For Geographic Comparison Tables (GCT) and Geographic Ranking Tables (GRT), the table file name is based on Table ID and Stub. 13 | 14 | 15 | Document descriptions: 16 | 17 | Data file: 18 | file name: .csv 19 | Includes the tabular data for the table. 20 | 21 | Annotation file: 22 | file name: _ann.csv 23 | This file contains cell annotations, which could be simple jam values, flag symbols, or codes of more complex cell annotations that replace the values in the data file. This file has a parallel structure to the data file, but it includes only those lines that correspond to the lines from the data file that have annotations. If there are no lines to be included in the annotation file, then the whole annotation file is omitted. A cell annotation starts with '$' or 'ECONF$', and the string that follows the '$' char is the jamming string or flag symbol. For example, '$1000+' is a simple cell annotation that would replace the content of the cell with the string '1000+'. A cell annotation that does not start with '$', such as 'ECONF$', is a code that is described in the notes file (see below). 24 | 25 | Notes file: 26 | file name: .txt 27 | This file contains the head notes, footnotes and the description of the cell annotations occurring in the data file (simple jamming cell annotations are excluded). 28 | 29 | Metadata file: 30 | file name: _metadata.csv 31 | This file contains the header information (transposed), without the data associated with the table. -------------------------------------------------------------------------------- /Dot_Plots/data/ACS_13_5YR_B20002/ACS_13_5YR_B20002.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plissonf/FlowingData/7a7115de92496cd422714dc353aa0c8a0f76c9f4/Dot_Plots/data/ACS_13_5YR_B20002/ACS_13_5YR_B20002.csv -------------------------------------------------------------------------------- /Dot_Plots/data/ACS_13_5YR_B20002/ACS_13_5YR_B20002.txt: -------------------------------------------------------------------------------- 1 | B20002 2 | MEDIAN EARNINGS IN THE PAST 12 MONTHS (IN 2013 INFLATION-ADJUSTED DOLLARS) BY SEX FOR THE POPULATION 16 YEARS AND OVER WITH EARNINGS IN THE PAST 12 MONTHS 3 | 4 | Universe: Population 16 years and over with earnings 5 | 6 | Although the American Community Survey (ACS) produces population, demographic and housing unit estimates, it is the Census Bureau's Population Estimates Program that produces and disseminates the official estimates of the population for the nation, states, counties, cities and towns and estimates of housing units for states and counties. 7 | 8 | 9 | Supporting documentation on code lists, subject definitions, data accuracy, and statistical testing can be found on the American Community Survey website in the Data and Documentation section. 10 | 11 | Sample size and data quality measures (including coverage rates, allocation rates, and response rates) can be found on the American Community Survey website in the Methodology section. 12 | 13 | 14 | Source: U.S. Census Bureau, 2009-2013 5-Year American Community Survey 15 | 16 | 17 | Explanation of Symbols:An '**' entry in the margin of error column indicates that either no sample observations or too few sample observations were available to compute a standard error and thus the margin of error. A statistical test is not appropriate. 18 | An '-' entry in the estimate column indicates that either no sample observations or too few sample observations were available to compute an estimate, or a ratio of medians cannot be calculated because one or both of the median estimates falls in the lowest interval or upper interval of an open-ended distribution. 19 | An '-' following a median estimate means the median falls in the lowest interval of an open-ended distribution. 20 | An '+' following a median estimate means the median falls in the upper interval of an open-ended distribution. 21 | An '***' entry in the margin of error column indicates that the median falls in the lowest interval or upper interval of an open-ended distribution. A statistical test is not appropriate. 22 | An '*****' entry in the margin of error column indicates that the estimate is controlled. A statistical test for sampling variability is not appropriate. 23 | An 'N' entry in the estimate and margin of error columns indicates that data for this geographic area cannot be displayed because the number of sample cases is too small. 24 | An '(X)' means that the estimate is not applicable or not available. 25 | 26 | 27 | Data are based on a sample and are subject to sampling variability. The degree of uncertainty for an estimate arising from sampling variability is represented through the use of a margin of error. The value shown here is the 90 percent margin of error. The margin of error can be interpreted roughly as providing a 90 percent probability that the interval defined by the estimate minus the margin of error and the estimate plus the margin of error (the lower and upper confidence bounds) contains the true value. In addition to sampling variability, the ACS estimates are subject to nonsampling error (for a discussion of nonsampling variability, see Accuracy of the Data). The effect of nonsampling error is not represented in these tables. 28 | 29 | 30 | While the 2009-2013 American Community Survey (ACS) data generally reflect the February 2013 Office of Management and Budget (OMB) definitions of metropolitan and micropolitan statistical areas; in certain instances the names, codes, and boundaries of the principal cities shown in ACS tables may differ from the OMB definitions due to differences in the effective dates of the geographic entities. 31 | 32 | 33 | Estimates of urban and rural population, housing units, and characteristics reflect boundaries of urban areas defined based on Census 2010 data. As a result, data for urban and rural areas from the ACS do not necessarily reflect the results of ongoing urbanization. 34 | 35 | 36 | -------------------------------------------------------------------------------- /Dot_Plots/data/ACS_13_5YR_B20002/ACS_13_5YR_B20002_metadata.csv: -------------------------------------------------------------------------------- 1 | GEO.id,Id 2 | GEO.id2,Id2 3 | GEO.display-label,Geography 4 | HD01_VD02,Estimate; Median earnings in the past 12 months (in 2013 inflation-adjusted dollars) -- - Total: 5 | HD02_VD02,Margin of Error; Median earnings in the past 12 months (in 2013 inflation-adjusted dollars) -- - Total: 6 | HD01_VD03,Estimate; Median earnings in the past 12 months (in 2013 inflation-adjusted dollars) -- - Male 7 | HD02_VD03,Margin of Error; Median earnings in the past 12 months (in 2013 inflation-adjusted dollars) -- - Male 8 | HD01_VD04,Estimate; Median earnings in the past 12 months (in 2013 inflation-adjusted dollars) -- - Female 9 | HD02_VD04,Margin of Error; Median earnings in the past 12 months (in 2013 inflation-adjusted dollars) -- - Female 10 | -------------------------------------------------------------------------------- /Dot_Plots/data/ACS_13_5YR_B20002/aff_download_readme.txt: -------------------------------------------------------------------------------- 1 | 2 | This zip file contains a number of documents containing materials related to the table which you have downloaded. These include: 3 | 1. aff_download_readme.txt (this file) 4 | 2. .csv (data file) 5 | 3. _ann.csv (annotation file, if applicable) 6 | 4. .txt (notes file) 7 | 5. _metadata.csv (metadata file) 8 | 9 | Naming convention: 10 | 11 | The table file name is based on the Table Id. 12 | For Geographic Comparison Tables (GCT) and Geographic Ranking Tables (GRT), the table file name is based on Table ID and Stub. 13 | 14 | 15 | Document descriptions: 16 | 17 | Data file: 18 | file name: .csv 19 | Includes the tabular data for the table. 20 | 21 | Annotation file: 22 | file name: _ann.csv 23 | This file contains cell annotations, which could be simple jam values, flag symbols, or codes of more complex cell annotations that replace the values in the data file. This file has a parallel structure to the data file, but it includes only those lines that correspond to the lines from the data file that have annotations. If there are no lines to be included in the annotation file, then the whole annotation file is omitted. A cell annotation starts with '$' or 'ECONF$', and the string that follows the '$' char is the jamming string or flag symbol. For example, '$1000+' is a simple cell annotation that would replace the content of the cell with the string '1000+'. A cell annotation that does not start with '$', such as 'ECONF$', is a code that is described in the notes file (see below). 24 | 25 | Notes file: 26 | file name: .txt 27 | This file contains the head notes, footnotes and the description of the cell annotations occurring in the data file (simple jamming cell annotations are excluded). 28 | 29 | Metadata file: 30 | file name: _metadata.csv 31 | This file contains the header information (transposed), without the data associated with the table. -------------------------------------------------------------------------------- /Dot_Plots/scatterplot-making.R: -------------------------------------------------------------------------------- 1 | ##### 2 | # 3 | # How to Make a Scatterplot 4 | # 5 | ##### 6 | 7 | 8 | # 9 | # Load data 10 | # 11 | 12 | income <- read.csv("data/ACS_13_1YR_S2401-by-occ.csv", stringsAsFactors=FALSE, sep=",") 13 | income1 <- subset(income, level == 1) 14 | 15 | # 16 | # Default dot plot 17 | # 18 | 19 | plot(income1$med_salary_male, income1$med_salary_female) 20 | 21 | 22 | 23 | # 24 | # Easier comparison 25 | # 26 | 27 | # Summary stat 28 | summary(income1) 29 | 30 | # Fixed axis limits 31 | plot(income1$med_salary_male, income1$med_salary_female, xlim=c(10000, 75000), ylim=c(10000, 75000)) 32 | 33 | 34 | 35 | # 36 | # Highlight 37 | # 38 | 39 | plot(income1$med_salary_male, income1$med_salary_female, xlim=c(10000, 75000), ylim=c(10000, 75000), asp=1) 40 | abline(0, 1) 41 | text(40000, 40000, "Equal median salary") 42 | text(60000, 30000, "Men make more") 43 | text(30000, 60000, "Women make more") 44 | 45 | 46 | # 47 | # Adjust 48 | # 49 | 50 | par(mar=c(5,6,3,2)) 51 | plot(income1$med_salary_male, income1$med_salary_female, xlim=c(10000, 75000), ylim=c(10000, 75000), asp=1, xlab="Men's Salary", ylab="", las=1, cex.axis=0.8, main="Median Salary Comparison by Occupation", bty="n", type="n") 52 | grid(NULL, NULL, lwd=1.2) 53 | points(income1$med_salary_male, income1$med_salary_female, pch=19) 54 | abline(0, 1, col="blue", lty=5) 55 | text(60000, 60000, "Equal median salary", srt=45, pos=3, offset=0.5, font=4, col="blue") 56 | text(60000, 30000, "MEN MAKE MORE", cex=0.8) 57 | text(30000, 60000, "WOMEN MAKE MORE", cex=0.8) 58 | title(ylab="Women's salary", line=4) 59 | 60 | 61 | # Different reference lines 62 | plot(income1$med_salary_male, income1$med_salary_female, xlim=c(10000, 75000), ylim=c(10000, 75000), asp=1, xlab="", ylab="", las=1, cex.axis=0.8, main="", bty="n", type="n") 63 | abline(0, 1, lty=1, lwd=2) 64 | text(60000, 60000, "Equal line", srt=45, pos=3, offset=0.5, font=4, col="black") 65 | 66 | for (prop in seq(0.2, 0.9, by=0.1)) { 67 | abline(0, prop, lty=3) 68 | text(60000, 60000*prop, paste(100*prop, "%", sep=""), srt=45*prop, pos=3, offset=0.5, font=4, col="darkgray") 69 | } 70 | 71 | 72 | 73 | 74 | 75 | # Point types for reference 76 | par(mar=c(0,2,2,2)) 77 | plot(0, 0, type="n", xlim=c(0,5.1), ylim=c(-0.5,2.1), axes=FALSE, xlab=NA, ylab=NA) 78 | row <- 2; column <- 0; currpch <- 0 79 | for (j in row:0) { 80 | for (i in column:5) { 81 | points(i, j, pch=currpch, cex=5) 82 | text(i, j-0.3, currpch, cex=0.8) 83 | currpch <- currpch + 1 84 | } 85 | 86 | } 87 | 88 | 89 | # 90 | # Overplotting problem 91 | # 92 | 93 | # Blob 94 | counties <- read.csv("data/ACS_13_5YR_B20002/ACS_13_5YR_B20002.csv", stringsAsFactors=FALSE) 95 | plot(counties$HD02_VD03, counties$HD02_VD04, xlim=c(0,60000), ylim=c(0,60000), asp=1) 96 | 97 | # Change opacity on points 98 | plot(counties$HD02_VD03, counties$HD02_VD04, xlim=c(0,60000), ylim=c(0,60000), type="n", asp=1) 99 | points(counties$HD02_VD03, counties$HD02_VD04, pch=20, col="#00000010") 100 | 101 | # Zoom in 102 | plot(counties$HD02_VD03, counties$HD02_VD04, xlim=c(0,10000), ylim=c(0,10000), type="n", asp=1, xlab="Men's salary", ylab="Women's salary", bty="n", main="Median Salary by County") 103 | grid(NULL, NULL, lwd=1.2) 104 | points(counties$HD02_VD03, counties$HD02_VD04, pch=20, col="#40000015") 105 | abline(0, 1, col="darkblue", lty=5) 106 | text(8000, 8000, "Equal median salary", srt=45, pos=3, offset=0.5, font=4, col="darkblue") 107 | 108 | 109 | 110 | # 111 | # Color 112 | # 113 | 114 | dotcol <- rep("#00000020", dim(counties)[1]) 115 | dotcol[counties$HD02_VD03 < counties$HD02_VD04] <- "#40000030" 116 | plot(counties$HD02_VD03, counties$HD02_VD04, xlim=c(0,10000), ylim=c(0,10000), type="n", asp=1, xlab="Men's salary", ylab="Women's salary", bty="n", main="Median Salary by County") 117 | grid(NULL, NULL, lwd=1.2) 118 | points(counties$HD02_VD03, counties$HD02_VD04, pch=20, col=dotcol, cex=0.8) 119 | abline(0, 1, col="darkblue", lty=5) 120 | -------------------------------------------------------------------------------- /Draw_in_R_+_Custom_Plots/drawing-tutorial.R: -------------------------------------------------------------------------------- 1 | #### 2 | # Draw shapes and custom plots 3 | #### 4 | 5 | # Fake data to use later. 6 | x.fakedata <- runif(20, 0, 100) 7 | y.fakedata <- runif(20, 0, 100) 8 | 9 | # Basic plot window. 10 | plot(0, 0, xlim=c(0, 100), ylim=c(0, 100), type="n", xlab=NA, ylab=NA) 11 | 12 | # From scratch. 13 | plot.new() 14 | plot.window(xlim=c(0, 100), ylim=c(0, 100)) 15 | ticks <- seq(0, 100, 20) 16 | par(las=1, cex=0.8) 17 | axis(1, at=ticks, labels=ticks, pos=0) 18 | axis(2, at=ticks, labels=ticks, pos=0) 19 | 20 | # Multiple plot windows. 21 | par(mfrow=c(2,3), mar=c(4,3,3,2), las=1, cex=0.6) 22 | for (i in 1:6) { 23 | plot.new() 24 | plot.window(xlim=c(0, 100), ylim=c(0, 100)) 25 | ticks <- seq(0, 100, 20) 26 | axis(1, at=ticks, labels=ticks, pos=0) 27 | axis(2, at=ticks, labels=ticks, pos=0) 28 | 29 | # Add symbols, shapes, and stuff. 30 | points(x.fakedata, y.fakedata, pch=18+i) 31 | # symbols(x.fakedata, y.fakedata, circles=x.fakedata, add=TRUE, inches=0.25) 32 | # symbols(x.fakedata, y.fakedata, squares=x.fakedata, add=TRUE, inches=0.25) 33 | } 34 | 35 | 36 | # Draw shapes. 37 | par(mfrow=c(1,2), las=1, cex=0.8) 38 | plot.new() 39 | plot.window(xlim=c(0, 100), ylim=c(0, 100)) 40 | ticks <- seq(0, 100, 20) 41 | axis(1, at=ticks, labels=ticks, pos=0) 42 | axis(2, at=ticks, labels=ticks, pos=0) 43 | 44 | 45 | # Draw your own shapes. 46 | x.oct <- c(40, 60, 80, 80, 60, 40, 20, 20, 40) 47 | y.oct <- c(80, 80, 60, 40, 20, 20, 40, 60, 80) 48 | polygon(x.oct, y.oct, col="#821122", border=NA) 49 | x.tri <- c(50, 60, 40, 50) 50 | y.tri <- c(60, 40, 40, 60) 51 | polygon(x.tri, y.tri, col="#f0f0f0", border="#ffffff", lwd=4) 52 | 53 | # Draw lines and segments. 54 | x.from <- seq(10, 90, by=10) 55 | y.from <- seq(10, 90, by=10) 56 | x.to <- seq(20, 100, by=10) 57 | y.to <- seq(10, 90, by=10) 58 | lines(x.from, y.from) 59 | segments(x.from, y.from, x.to, y.to) 60 | segments(x.from, y.from, x.to, y.to, lty=2) 61 | 62 | 63 | # Text 64 | plot.new() 65 | plot.window(xlim=c(0, 100), ylim=c(0, 100)) 66 | ticks <- seq(0, 100, 20) 67 | par(las=1, cex=0.8) 68 | axis(1, at=ticks, labels=ticks, pos=0) 69 | axis(2, at=ticks, labels=ticks, pos=0) 70 | #text(x.fakedata, y.fakedata, round(x.fakedata)) 71 | for (i in 1:length(x.fakedata)) { 72 | thesize <- 4*x.fakedata[i]/100 73 | thelabel <- round(x.fakedata[i]) 74 | text(x.fakedata[i], y.fakedata[i], thelabel, cex=thesize, col="#333333") 75 | } 76 | mtext("x axis", side=1, font=2) 77 | mtext("y axis", side=2, font=2) 78 | 79 | 80 | # Apply to make sparklines. 81 | par(mfrow=c(10, 3), xpd=NA, mar=c(2,0.5,2,0.5), lwd=0.5, cex=0.5) 82 | colors <- c("#09c912", "#f40053", "#4ba9fd") 83 | for (i in 1:30) { 84 | plot.new() 85 | plot.window(xlim=c(0, 50), ylim=c(0, 1)) 86 | # axis(1, lwd=0.5) 87 | fakedata <- runif(50) 88 | colindex <- (i %% 3) + 1 89 | rect(0:49, 0, 1:50, fakedata, border=NA, col=colors[colindex]) 90 | segments(c(10, 40), c(2, 2), c(10, 40), c(-2, -2), col="black", lwd=0.7, lty=3) 91 | mtext(i, side=3, adj=0, cex=0.5, font=2) 92 | } 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /Heatmap/nba_heatmap.R: -------------------------------------------------------------------------------- 1 | nba <- read.csv("ppg2008.csv", sep=",") 2 | 3 | nba <- nba[order(nba$PTS),] 4 | row.names(nba) <- nba$Name 5 | nba <- nba[,2:20] 6 | 7 | nba_matrix <- data.matrix(nba) 8 | nba_heatmap <- heatmap(nba_matrix, Rowv=NA, Colv=NA, col = brewer.pal(9, "Blues"), scale="column", margins=c(5,10)) 9 | -------------------------------------------------------------------------------- /Heatmap/nba_heatmap_revised.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plissonf/FlowingData/7a7115de92496cd422714dc353aa0c8a0f76c9f4/Heatmap/nba_heatmap_revised.pdf -------------------------------------------------------------------------------- /Heatmap/ppg2008.csv: -------------------------------------------------------------------------------- 1 | Name ,G,MIN,PTS,FGM,FGA,FGP,FTM,FTA,FTP,3PM,3PA,3PP,ORB,DRB,TRB,AST,STL,BLK,TO,PF 2 | Dwyane Wade ,79,38.6,30.2,10.8,22,0.491,7.5,9.8,0.765,1.1,3.5,0.317,1.1,3.9,5,7.5,2.2,1.3,3.4,2.3 3 | LeBron James ,81,37.7,28.4,9.7,19.9,0.489,7.3,9.4,0.78,1.6,4.7,0.344,1.3,6.3,7.6,7.2,1.7,1.1,3,1.7 4 | Kobe Bryant ,82,36.2,26.8,9.8,20.9,0.467,5.9,6.9,0.856,1.4,4.1,0.351,1.1,4.1,5.2,4.9,1.5,0.5,2.6,2.3 5 | Dirk Nowitzki ,81,37.7,25.9,9.6,20,0.479,6,6.7,0.89,0.8,2.1,0.359,1.1,7.3,8.4,2.4,0.8,0.8,1.9,2.2 6 | Danny Granger ,67,36.2,25.8,8.5,19.1,0.447,6,6.9,0.878,2.7,6.7,0.404,0.7,4.4,5.1,2.7,1,1.4,2.5,3.1 7 | Kevin Durant ,74,39,25.3,8.9,18.8,0.476,6.1,7.1,0.863,1.3,3.1,0.422,1,5.5,6.5,2.8,1.3,0.7,3,1.8 8 | Kevin Martin ,51,38.2,24.6,6.7,15.9,0.42,9,10.3,0.867,2.3,5.4,0.415,0.6,3,3.6,2.7,1.2,0.2,2.9,2.3 9 | Al Jefferson ,50,36.6,23.1,9.7,19.5,0.497,3.7,5,0.738,0,0.1,0,3.4,7.5,11,1.6,0.8,1.7,1.8,2.8 10 | Chris Paul ,78,38.5,22.8,8.1,16.1,0.503,5.8,6.7,0.868,0.8,2.3,0.364,0.9,4.7,5.5,11,2.8,0.1,3,2.7 11 | Carmelo Anthony ,66,34.5,22.8,8.1,18.3,0.443,5.6,7.1,0.793,1,2.6,0.371,1.6,5.2,6.8,3.4,1.1,0.4,3,3 12 | Chris Bosh ,77,38.1,22.7,8,16.4,0.487,6.5,8,0.817,0.2,0.6,0.245,2.8,7.2,10,2.5,0.9,1,2.3,2.5 13 | Brandon Roy ,78,37.2,22.6,8.1,16.9,0.48,5.3,6.5,0.824,1.1,2.8,0.377,1.3,3.4,4.7,5.1,1.1,0.3,1.9,1.6 14 | Antawn Jamison ,81,38.2,22.2,8.3,17.8,0.468,4.2,5.6,0.754,1.4,3.9,0.351,2.4,6.5,8.9,1.9,1.2,0.3,1.5,2.7 15 | Tony Parker ,72,34.1,22,8.9,17.5,0.506,3.9,5,0.782,0.3,0.9,0.292,0.4,2.7,3.1,6.9,0.9,0.1,2.6,1.5 16 | Amare Stoudemire ,53,36.8,21.4,7.6,14.1,0.539,6.1,7.3,0.835,0.1,0.1,0.429,2.2,5.9,8.1,2,0.9,1.1,2.8,3.1 17 | Joe Johnson ,79,39.5,21.4,7.8,18,0.437,3.8,4.6,0.826,1.9,5.2,0.36,0.8,3.6,4.4,5.8,1.1,0.2,2.5,2.2 18 | Devin Harris ,69,36.1,21.3,6.6,15.1,0.438,7.2,8.8,0.82,0.9,3.2,0.291,0.4,2.9,3.3,6.9,1.7,0.2,3.1,2.4 19 | Michael Redd ,33,36.4,21.2,7.5,16.6,0.455,4,4.9,0.814,2.1,5.8,0.366,0.7,2.5,3.2,2.7,1.1,0.1,1.6,1.4 20 | David West ,76,39.3,21,8,17,0.472,4.8,5.5,0.884,0.1,0.3,0.24,2.1,6.4,8.5,2.3,0.6,0.9,2.1,2.7 21 | Zachary Randolph ,50,35.1,20.8,8.3,17.5,0.475,3.6,4.9,0.734,0.6,1.9,0.33,3.1,6.9,10.1,2.1,0.9,0.3,2.3,2.7 22 | Caron Butler ,67,38.6,20.8,7.3,16.2,0.453,5.1,6,0.858,1,3.1,0.31,1.8,4.4,6.2,4.3,1.6,0.3,3.1,2.5 23 | Vince Carter ,80,36.8,20.8,7.4,16.8,0.437,4.2,5.1,0.817,1.9,4.9,0.385,0.9,4.2,5.1,4.7,1,0.5,2.1,2.9 24 | Stephen Jackson ,59,39.7,20.7,7,16.9,0.414,5,6,0.826,1.7,5.2,0.338,1.2,3.9,5.1,6.5,1.5,0.5,3.9,2.6 25 | Ben Gordon ,82,36.6,20.7,7.3,16,0.455,4,4.7,0.864,2.1,5.1,0.41,0.6,2.8,3.5,3.4,0.9,0.3,2.4,2.2 26 | Dwight Howard ,79,35.7,20.6,7.1,12.4,0.572,6.4,10.7,0.594,0,0,0,4.3,9.6,13.8,1.4,1,2.9,3,3.4 27 | Paul Pierce ,81,37.4,20.5,6.7,14.6,0.457,5.7,6.8,0.83,1.5,3.8,0.391,0.7,5,5.6,3.6,1,0.3,2.8,2.7 28 | Al Harrington ,73,34.9,20.1,7.3,16.6,0.439,3.2,4,0.793,2.3,6.4,0.364,1.4,4.9,6.2,1.4,1.2,0.3,2.2,3.1 29 | Jamal Crawford ,65,38.1,19.7,6.4,15.7,0.41,4.6,5.3,0.872,2.2,6.1,0.36,0.4,2.6,3,4.4,0.9,0.2,2.3,1.4 30 | Yao Ming ,77,33.6,19.7,7.4,13.4,0.548,4.9,5.7,0.866,0,0,1,2.6,7.2,9.9,1.8,0.4,1.9,3,3.3 31 | Richard Jefferson ,82,35.9,19.6,6.5,14.9,0.439,5.1,6.3,0.805,1.4,3.6,0.397,0.7,3.9,4.6,2.4,0.8,0.2,2,3.1 32 | Jason Terry ,74,33.6,19.6,7.3,15.8,0.463,2.7,3,0.88,2.3,6.2,0.366,0.5,1.9,2.4,3.4,1.3,0.3,1.6,1.9 33 | Deron Williams ,68,36.9,19.4,6.8,14.5,0.471,4.8,5.6,0.849,1,3.3,0.31,0.4,2.5,2.9,10.7,1.1,0.3,3.4,2 34 | Tim Duncan ,75,33.7,19.3,7.4,14.8,0.504,4.5,6.4,0.692,0,0,0,2.7,8,10.7,3.5,0.5,1.7,2.2,2.3 35 | Monta Ellis ,25,35.6,19,7.8,17.2,0.451,3.1,3.8,0.83,0.3,1,0.308,0.6,3.8,4.3,3.7,1.6,0.3,2.7,2.7 36 | Rudy Gay ,79,37.3,18.9,7.2,16,0.453,3.3,4.4,0.767,1.1,3.1,0.351,1.4,4.2,5.5,1.7,1.2,0.7,2.6,2.8 37 | Pau Gasol ,81,37.1,18.9,7.3,12.9,0.567,4.2,5.4,0.781,0,0,0.5,3.2,6.4,9.6,3.5,0.6,1,1.9,2.1 38 | Andre Iguodala ,82,39.8,18.8,6.6,14,0.473,4.6,6.4,0.724,1,3.2,0.307,1.1,4.6,5.7,5.3,1.6,0.4,2.7,1.9 39 | Corey Maggette ,51,31.1,18.6,5.7,12.4,0.461,6.7,8.1,0.824,0.5,1.9,0.253,1,4.6,5.5,1.8,0.9,0.2,2.4,3.8 40 | O.J. Mayo ,82,38,18.5,6.9,15.6,0.438,3,3.4,0.879,1.8,4.6,0.384,0.7,3.1,3.8,3.2,1.1,0.2,2.8,2.5 41 | John Salmons ,79,37.5,18.3,6.5,13.8,0.472,3.6,4.4,0.83,1.6,3.8,0.417,0.7,3.5,4.2,3.2,1.1,0.3,2.1,2.3 42 | Richard Hamilton ,67,34,18.3,7,15.6,0.447,3.3,3.9,0.848,1,2.8,0.368,0.7,2.4,3.1,4.4,0.6,0.1,2,2.6 43 | Ray Allen ,79,36.3,18.2,6.3,13.2,0.48,3,3.2,0.952,2.5,6.2,0.409,0.8,2.7,3.5,2.8,0.9,0.2,1.7,2 44 | LaMarcus Aldridge ,81,37.1,18.1,7.4,15.3,0.484,3.2,4.1,0.781,0.1,0.3,0.25,2.9,4.6,7.5,1.9,1,1,1.5,2.6 45 | Josh Howard ,52,31.9,18,6.8,15.1,0.451,3.3,4.2,0.782,1.1,3.2,0.345,1.1,3.9,5.1,1.6,1.1,0.6,1.7,2.6 46 | Maurice Williams ,81,35,17.8,6.5,13.9,0.467,2.6,2.8,0.912,2.3,5.2,0.436,0.6,2.9,3.4,4.1,0.9,0.1,2.2,2.7 47 | Shaquille O'neal ,75,30.1,17.8,6.8,11.2,0.609,4.1,6.9,0.595,0,0,0,2.5,5.9,8.4,1.7,0.7,1.4,2.2,3.4 48 | Rashard Lewis ,79,36.2,17.7,6.1,13.8,0.439,2.8,3.4,0.836,2.8,7,0.397,1.2,4.6,5.7,2.6,1,0.6,2,2.5 49 | Chauncey Billups ,79,35.3,17.7,5.2,12.4,0.418,5.3,5.8,0.913,2.1,5,0.408,0.4,2.6,3,6.4,1.2,0.2,2.2,2 50 | Allen Iverson ,57,36.7,17.5,6.1,14.6,0.417,4.8,6.1,0.781,0.5,1.7,0.283,0.5,2.5,3,5,1.5,0.1,2.6,1.5 51 | Nate Robinson ,74,29.9,17.2,6.1,13.9,0.437,3.4,4,0.841,1.7,5.2,0.325,1.3,2.6,3.9,4.1,1.3,0.1,1.9,2.8 -------------------------------------------------------------------------------- /Heatmap_2/heatmaps-custom.R: -------------------------------------------------------------------------------- 1 | # Standard heat map (More details here: http://datafl.ws/2x) 2 | leaders <- read.csv("http://datasets.flowingdata.com/ppg2008.csv", sep=",") 3 | leaders <- leaders[order(leaders$PTS),] 4 | row.names(leaders) <- leaders$Name 5 | leaders <- leaders[,2:20] 6 | nba_matrix <- data.matrix(leaders) 7 | heatmap(nba_matrix, Rowv=NA, Colv=NA, col = cm.colors(256), scale="column", margins=c(5,10)) 8 | 9 | 10 | 11 | 12 | # Load play-by-play data. 13 | nba <- read.csv("data/2008-09nba.trunc.csv", sep=",") 14 | shots <- nba[nba$etype == "shot",] 15 | 16 | # Take a quick look. 17 | shots[1:10,] 18 | 19 | # Some are NA. Get only known shots. 20 | shots.known <- shots[!is.na(shots$x) & !is.na(shots$y),] 21 | 22 | # Golden State Warriors shots 23 | gsw <- subset(shots.known, team == "GSW") 24 | 25 | # Basic symbol shot chart. 26 | symbols(gsw$x, gsw$y, circles=rep(1,length(gsw$x)), asp=1, inches=FALSE) 27 | 28 | # Aggregate by shot frequency 29 | library(plyr) 30 | gsw.agg <- count(gsw, c("x","y")) 31 | 32 | # Size symbols by number of shots. 33 | symbols(gsw.agg$x, gsw.agg$y, circles=sqrt(gsw.agg$freq)/8, asp=1, inches=FALSE, ylim=c(0,40)) 34 | symbols(gsw.agg$x, gsw.agg$y, squares=sqrt(gsw.agg$freq)/8, asp=1, inches=FALSE, ylim=c(0,40)) 35 | 36 | # Hexbins 37 | library(hexbin) 38 | h <- hexbin(gsw$x, gsw$y, xbins=20, shape=80/50) 39 | plot(h) 40 | 41 | 42 | # Helper function to get color by shot frequency 43 | getColor <- function(val) { 44 | 45 | minVal <- log(1) # Using logarithmic scale 46 | maxVal <- log(1065) 47 | 48 | numCols <- 20 49 | pal <- colorRampPalette(c("#f4d5d0", "#692518")) 50 | cols <- pal(numCols) 51 | 52 | # Get index to pick color. 53 | colIndex <- round(numCols * (log(val) - minVal) / (maxVal - minVal)) 54 | colIndex <- max(1, colIndex) 55 | 56 | return(cols[colIndex]) 57 | } 58 | 59 | # Get colors and draw heat map of shot frequency. 60 | gridColors <- sapply(gsw.agg$freq, getColor) 61 | symbols(gsw.agg$x, gsw.agg$y, squares=rep(1,length(gsw.agg$x)), asp=1, inches=FALSE, ylim=c(0,40), bg=gridColors, fg=NA) 62 | 63 | 64 | 65 | # Find points per shot for each spot on court. 66 | ptsper <- c() 67 | for (i in 1:length(gsw.agg[,1])) { 68 | 69 | xcoord <- gsw.agg$x[i] 70 | ycoord <- gsw.agg$y[i] 71 | spot <- subset(gsw, x == xcoord & y == ycoord) 72 | totalShots <- length(spot[,1]) 73 | totalPts <- sum(spot$points[!is.na(spot$points)]) 74 | 75 | ptsper <- c(ptsper, totalPts/totalShots) 76 | } 77 | 78 | 79 | 80 | # Helper function to get color by points per shot. 81 | getColorByPoints <- function(val) { 82 | 83 | minVal <- 0 84 | maxVal <- 3 85 | 86 | numCols <- 30 87 | 88 | pal <- colorRampPalette(c("#eddfab", "#d86853")) 89 | cols <- pal(numCols) 90 | 91 | # Get index to pick color. 92 | colIndex <- round(numCols * (val - minVal) / (maxVal - minVal)) 93 | colIndex <- max(1, colIndex) 94 | 95 | return(cols[colIndex]) 96 | } 97 | 98 | # Get colors and draw heat map of points per shot. 99 | gridColors <- sapply(ptsper, getColorByPoints) 100 | plot(0, 0, xlim=c(0,50), ylim=c(0,40), type="n", xaxt="n", yaxt="n", xlab="", ylab="", bty="n") 101 | symbols(gsw.agg$x, gsw.agg$y, squares=sqrt(gsw.agg$freq)/3, asp=1, inches=FALSE, add=TRUE, bg=gridColors, fg=NA) 102 | 103 | 104 | 105 | # Adding an NBA court outline for kicks and giggles. 106 | draw.arc(25, 5.25, 9/12, angle1=0, angle2=2*pi, col="#cccccc", lwd=2) # Hoop 107 | lines(c(22,28), c(4,4), col="#cccccc", lwd=2) # Backboard 108 | lines(c(2.5, 2.5), c(0, 13.5), col="#cccccc", lwd=2) # Side 3-pt 109 | lines(c(47.5, 47.5), c(0, 13.5), col="#cccccc", lwd=2) 110 | lines(c(19,19), c(0,19), col="#cccccc", lwd=2) # Inside lane 111 | lines(c(31,31), c(0,19), col="#cccccc", lwd=2) 112 | lines(c(19,31), c(19,19), col="#cccccc", lwd=2) # Free throw 113 | lines(c(0,50),c(0,0), col="#cccccc", lwd=2) # Baseline 114 | draw.arc(25, 5.25, 23.75, angle1=pi/9.8, angle2=pi/1.113, col="#cccccc", lwd=2) # 3-pt arc 115 | 116 | 117 | -------------------------------------------------------------------------------- /Interactive_Choropleth_Map/interactivemap/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Interactive Choropleth Map 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 |
15 |

Unemployment Rate

16 |

September 2012, seasonally adjusted

17 |
18 | 19 |
20 | 21 |
22 | 23 |
24 |

This is an example of an interactive choropleth map. See the tutorial for details on how to do this with your own data.

25 |
26 | 27 |
28 | 29 |
30 |
31 | 32 | 33 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /Interactive_Choropleth_Map/interactivemap/reset.css: -------------------------------------------------------------------------------- 1 | html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent;}body{line-height:1;}ol,ul{list-style:none;}blockquote,q{quotes:none;}:focus{outline:0;}ins{text-decoration:none;}del{text-decoration:line-through;}table{border-collapse:collapse;border-spacing:0;} -------------------------------------------------------------------------------- /Interactive_Choropleth_Map/interactivemap/unemp.css: -------------------------------------------------------------------------------- 1 | #mainwrapper { 2 | padding: 20px; 3 | font-size: 14px; 4 | font-family: "Century Gothic", "Helvectica", Arial, sans-serif; 5 | } 6 | #mainwrapper h1 { 7 | font-size: 2.0em; 8 | margin-bottom: 0.3em; 9 | } 10 | #leadin { 11 | margin-bottom: 2.0em; 12 | } 13 | #direct p { 14 | margin-top: 2.0em; 15 | background: #e0e0e0; 16 | padding: 0.4em; 17 | width: 900px; 18 | } 19 | 20 | #tooltip { 21 | position: absolute; 22 | background: #000; 23 | color: #fff; 24 | padding: 10px; 25 | font-family: "Century Gothic", "Helvectica", Arial, sans-serif; 26 | } 27 | #tooltip h3 { 28 | font-size: 1.0em; 29 | margin-bottom: 0.5em; 30 | padding-bottom: 0.3em; 31 | border-bottom: 1px solid #fff; 32 | } 33 | #tooltip p { 34 | font-size: 0.9em; 35 | } 36 | 37 | 38 | .clr { clear: both; } -------------------------------------------------------------------------------- /Interactive_Choropleth_Map/interactivemap/unemp.json: -------------------------------------------------------------------------------- 1 | { "states": [{"abbrev":"AL","name":"Alabama","unemprate":8.3}, 2 | {"abbrev":"AK","name":"Alaska","unemprate":7.5}, 3 | {"abbrev":"AZ","name":"Arizona","unemprate":8.2}, 4 | {"abbrev":"AR","name":"Arkansas","unemprate":7.1}, 5 | {"abbrev":"CA","name":"California","unemprate":10.2}, 6 | {"abbrev":"CO","name":"Colorado","unemprate":8}, 7 | {"abbrev":"CT","name":"Connecticut","unemprate":8.9}, 8 | {"abbrev":"DE","name":"Delaware","unemprate":6.8}, 9 | {"abbrev":"DC","name":"Distric of Columbia","unemprate":8.7}, 10 | {"abbrev":"FL","name":"Florida","unemprate":8.7}, 11 | {"abbrev":"GA","name":"Georgia","unemprate":9}, 12 | {"abbrev":"HI","name":"Hawaii","unemprate":5.7}, 13 | {"abbrev":"ID","name":"Idaho","unemprate":7.1}, 14 | {"abbrev":"IL","name":"Illinois","unemprate":8.8}, 15 | {"abbrev":"IN","name":"Indiana","unemprate":8.2}, 16 | {"abbrev":"IA","name":"Iowa","unemprate":5.2}, 17 | {"abbrev":"KS","name":"Kansas","unemprate":5.9}, 18 | {"abbrev":"KY","name":"Kentucky","unemprate":8.4}, 19 | {"abbrev":"LA","name":"Louisiana","unemprate":7}, 20 | {"abbrev":"ME","name":"Maine","unemprate":7.6}, 21 | {"abbrev":"MD","name":"Maryland","unemprate":6.9}, 22 | {"abbrev":"MA","name":"Massachusettes","unemprate":6.5}, 23 | {"abbrev":"MI","name":"Michigan","unemprate":9.3}, 24 | {"abbrev":"MN","name":"Minnesota","unemprate":5.8}, 25 | {"abbrev":"MS","name":"Mississippi","unemprate":9.2}, 26 | {"abbrev":"MO","name":"Missouri","unemprate":6.9}, 27 | {"abbrev":"MT","name":"Montana","unemprate":6.1}, 28 | {"abbrev":"NE","name":"Nebraska","unemprate":3.9}, 29 | {"abbrev":"NV","name":"Nevada","unemprate":11.8}, 30 | {"abbrev":"NH","name":"New Hampshire","unemprate":5.7}, 31 | {"abbrev":"NJ","name":"New Jersey","unemprate":9.8}, 32 | {"abbrev":"NM","name":"New Mexico","unemprate":6.4}, 33 | {"abbrev":"NY","name":"New York","unemprate":8.9}, 34 | {"abbrev":"NC","name":"North Carolina","unemprate":9.6}, 35 | {"abbrev":"ND","name":"North Dakota","unemprate":3}, 36 | {"abbrev":"OH","name":"Ohio","unemprate":7}, 37 | {"abbrev":"OK","name":"Oklahoma","unemprate":5.2}, 38 | {"abbrev":"OR","name":"Oregon","unemprate":8.7}, 39 | {"abbrev":"PA","name":"Pennsylvania","unemprate":8.2}, 40 | {"abbrev":"RI","name":"Rhode Island","unemprate":10.5}, 41 | {"abbrev":"SC","name":"South Carolina","unemprate":9.1}, 42 | {"abbrev":"SD","name":"South Dakota","unemprate":4.4}, 43 | {"abbrev":"TN","name":"Tennessee","unemprate":8.3}, 44 | {"abbrev":"TX","name":"Texas","unemprate":6.8}, 45 | {"abbrev":"UT","name":"Utah","unemprate":5.4}, 46 | {"abbrev":"VT","name":"Vermont","unemprate":5.4}, 47 | {"abbrev":"VA","name":"Virginia","unemprate":5.9}, 48 | {"abbrev":"WA","name":"Washington","unemprate":8.5}, 49 | {"abbrev":"WV","name":"West Virginia","unemprate":7.6}, 50 | {"abbrev":"WI","name":"Wisconsin","unemprate":7.3}, 51 | {"abbrev":"WY","name":"Wyoming","unemprate":5.4}] } -------------------------------------------------------------------------------- /Interactive_Choropleth_Map/interactivemap/zoomandpan.js: -------------------------------------------------------------------------------- 1 | // Zooming 2 | rsr.setViewBox(0, 0, rsr.width, rsr.height); 3 | var viewBoxWidth = rsr.width; 4 | var viewBoxHeight = rsr.height; 5 | var canvasID = "#map"; 6 | var startX, startY; 7 | var mousedown = false; 8 | var dX, dY; 9 | var oX = 0, oY = 0, oWidth = viewBoxWidth, oHeight = viewBoxHeight; 10 | var currzoom = 0; 11 | 12 | var viewBox = rsr.setViewBox(oX, oY, viewBoxWidth, viewBoxHeight); 13 | viewBox.X = oX; 14 | viewBox.Y = oY; 15 | 16 | // Helper function to handle zooming changes 17 | function handle(delta) { 18 | vBHo = viewBoxHeight; 19 | vBWo = viewBoxWidth; 20 | 21 | if (delta < 0) { 22 | if (viewBoxWidth < 350) return; 23 | viewBoxWidth *= 0.95; 24 | viewBoxHeight*= 0.95; 25 | } 26 | else { 27 | if (viewBoxWidth > rsr.width) return; 28 | viewBoxWidth *= 1.05; 29 | viewBoxHeight *= 1.05; 30 | } 31 | 32 | viewBox.X -= (viewBoxWidth - vBWo) / 2; 33 | viewBox.Y -= (viewBoxHeight - vBHo) / 2; 34 | rsr.setViewBox(viewBox.X, viewBox.Y, viewBoxWidth, viewBoxHeight); 35 | } 36 | 37 | 38 | // Event handler for mouse wheel zooming 39 | function wheel(event) { 40 | var delta = 0; 41 | if (!event) /* For IE. */ 42 | event = window.event; 43 | 44 | if (event.wheelDelta) { /* IE/Opera. */ 45 | delta = event.wheelDelta/120; 46 | } else if (event.detail) { /** Mozilla case. */ 47 | /** In Mozilla, sign of delta is different than in IE. 48 | * Also, delta is multiple of 3. 49 | */ 50 | delta = -event.detail/3; 51 | } 52 | 53 | /** If delta is nonzero, handle it. 54 | * Basically, delta is now positive if wheel was scrolled up, 55 | * and negative, if wheel was scrolled down. 56 | */ 57 | if (delta) { 58 | handle(delta); 59 | $(tooltip).hide(); 60 | } 61 | 62 | 63 | /** Prevent default actions caused by mouse wheel. 64 | * That might be ugly, but we handle scrolls somehow 65 | * anyway, so don't bother here.. 66 | */ 67 | if (event.preventDefault) 68 | event.preventDefault(); 69 | 70 | event.returnValue = false; 71 | } 72 | 73 | 74 | // Initialization and add listeners. 75 | if (window.addEventListener) 76 | /** DOMMouseScroll is for mozilla. */ 77 | window.addEventListener('DOMMouseScroll', wheel, false); 78 | 79 | /** IE/Opera. */ 80 | window.onmousewheel = document.onmousewheel = wheel; 81 | 82 | // Add event handling for mouse actions. 83 | $(canvasID).mousedown(function(e) { 84 | mousedown = true; 85 | startX = e.pageX; 86 | startY = e.pageY; 87 | }); 88 | 89 | $(canvasID).mousemove(function(e) { 90 | if (mousedown == false) { return; } 91 | dX = startX - e.pageX; 92 | dY = startY - e.pageY; 93 | x = viewBoxWidth / rsr.width; 94 | y = viewBoxHeight / rsr.height; 95 | dX *= x; 96 | dY *= y; 97 | rsr.setViewBox(viewBox.X + dX, viewBox.Y + dY, viewBoxWidth, viewBoxHeight); 98 | }); 99 | 100 | $(canvasID).mouseup(function(e) { 101 | if (mousedown == false) return; 102 | viewBox.X += dX; 103 | viewBox.Y += dY; 104 | mousedown = false; 105 | }); -------------------------------------------------------------------------------- /Line_Charts/data/country-regions.csv: -------------------------------------------------------------------------------- 1 | CountryCode,RegionCode,RegionName 2 | AFG,SAS,South Asia 3 | ALB,ECS,Europe & Central Asia (all income levels) 4 | DZA,MEA,Middle East & North Africa (all income levels) 5 | AGO,SSF,Sub-Saharan Africa (all income levels) 6 | ARG,LCN,Latin America & Caribbean (all income levels) 7 | ARM,ECS,Europe & Central Asia (all income levels) 8 | ABW,LCN,Latin America & Caribbean (all income levels) 9 | AUS,EAS,East Asia & Pacific (all income levels) 10 | AUT,ECS,Europe & Central Asia (all income levels) 11 | AZE,ECS,Europe & Central Asia (all income levels) 12 | BHS,LCN,Latin America & Caribbean (all income levels) 13 | BHR,MEA,Middle East & North Africa (all income levels) 14 | BGD,SAS,South Asia 15 | BRB,LCN,Latin America & Caribbean (all income levels) 16 | BLR,ECS,Europe & Central Asia (all income levels) 17 | BEL,ECS,Europe & Central Asia (all income levels) 18 | BLZ,LCN,Latin America & Caribbean (all income levels) 19 | BEN,SSF,Sub-Saharan Africa (all income levels) 20 | BTN,SAS,South Asia 21 | BOL,LCN,Latin America & Caribbean (all income levels) 22 | BIH,ECS,Europe & Central Asia (all income levels) 23 | BWA,SSF,Sub-Saharan Africa (all income levels) 24 | BRA,LCN,Latin America & Caribbean (all income levels) 25 | BRN,EAS,East Asia & Pacific (all income levels) 26 | BGR,ECS,Europe & Central Asia (all income levels) 27 | BFA,SSF,Sub-Saharan Africa (all income levels) 28 | BDI,SSF,Sub-Saharan Africa (all income levels) 29 | KHM,EAS,East Asia & Pacific (all income levels) 30 | CMR,SSF,Sub-Saharan Africa (all income levels) 31 | CAN,NAC,North America 32 | CPV,SSF,Sub-Saharan Africa (all income levels) 33 | CAF,SSF,Sub-Saharan Africa (all income levels) 34 | TCD,SSF,Sub-Saharan Africa (all income levels) 35 | CHI,ECS,Europe & Central Asia (all income levels) 36 | CHL,LCN,Latin America & Caribbean (all income levels) 37 | CHN,EAS,East Asia & Pacific (all income levels) 38 | COL,LCN,Latin America & Caribbean (all income levels) 39 | COM,SSF,Sub-Saharan Africa (all income levels) 40 | COD,SSF,Sub-Saharan Africa (all income levels) 41 | COG,SSF,Sub-Saharan Africa (all income levels) 42 | CRI,LCN,Latin America & Caribbean (all income levels) 43 | CIV,SSF,Sub-Saharan Africa (all income levels) 44 | HRV,ECS,Europe & Central Asia (all income levels) 45 | CUB,LCN,Latin America & Caribbean (all income levels) 46 | CYP,ECS,Europe & Central Asia (all income levels) 47 | CZE,ECS,Europe & Central Asia (all income levels) 48 | DNK,ECS,Europe & Central Asia (all income levels) 49 | DJI,MEA,Middle East & North Africa (all income levels) 50 | DOM,LCN,Latin America & Caribbean (all income levels) 51 | ECU,LCN,Latin America & Caribbean (all income levels) 52 | EGY,MEA,Middle East & North Africa (all income levels) 53 | SLV,LCN,Latin America & Caribbean (all income levels) 54 | GNQ,SSF,Sub-Saharan Africa (all income levels) 55 | ERI,SSF,Sub-Saharan Africa (all income levels) 56 | EST,ECS,Europe & Central Asia (all income levels) 57 | ETH,SSF,Sub-Saharan Africa (all income levels) 58 | FJI,EAS,East Asia & Pacific (all income levels) 59 | FIN,ECS,Europe & Central Asia (all income levels) 60 | FRA,ECS,Europe & Central Asia (all income levels) 61 | PYF,EAS,East Asia & Pacific (all income levels) 62 | GAB,SSF,Sub-Saharan Africa (all income levels) 63 | GMB,SSF,Sub-Saharan Africa (all income levels) 64 | GEO,ECS,Europe & Central Asia (all income levels) 65 | DEU,ECS,Europe & Central Asia (all income levels) 66 | GHA,SSF,Sub-Saharan Africa (all income levels) 67 | GRC,ECS,Europe & Central Asia (all income levels) 68 | GRD,LCN,Latin America & Caribbean (all income levels) 69 | GUM,EAS,East Asia & Pacific (all income levels) 70 | GTM,LCN,Latin America & Caribbean (all income levels) 71 | GIN,SSF,Sub-Saharan Africa (all income levels) 72 | GNB,SSF,Sub-Saharan Africa (all income levels) 73 | GUY,LCN,Latin America & Caribbean (all income levels) 74 | HTI,LCN,Latin America & Caribbean (all income levels) 75 | HND,LCN,Latin America & Caribbean (all income levels) 76 | HKG,EAS,East Asia & Pacific (all income levels) 77 | HUN,ECS,Europe & Central Asia (all income levels) 78 | ISL,ECS,Europe & Central Asia (all income levels) 79 | IND,SAS,South Asia 80 | IDN,EAS,East Asia & Pacific (all income levels) 81 | IRN,MEA,Middle East & North Africa (all income levels) 82 | IRQ,MEA,Middle East & North Africa (all income levels) 83 | IRL,ECS,Europe & Central Asia (all income levels) 84 | ISR,MEA,Middle East & North Africa (all income levels) 85 | ITA,ECS,Europe & Central Asia (all income levels) 86 | JAM,LCN,Latin America & Caribbean (all income levels) 87 | JPN,EAS,East Asia & Pacific (all income levels) 88 | JOR,MEA,Middle East & North Africa (all income levels) 89 | KAZ,ECS,Europe & Central Asia (all income levels) 90 | KEN,SSF,Sub-Saharan Africa (all income levels) 91 | PRK,EAS,East Asia & Pacific (all income levels) 92 | KOR,EAS,East Asia & Pacific (all income levels) 93 | KSV,ECS,Europe & Central Asia (all income levels) 94 | KWT,MEA,Middle East & North Africa (all income levels) 95 | KGZ,ECS,Europe & Central Asia (all income levels) 96 | LAO,EAS,East Asia & Pacific (all income levels) 97 | LVA,ECS,Europe & Central Asia (all income levels) 98 | LBN,MEA,Middle East & North Africa (all income levels) 99 | LSO,SSF,Sub-Saharan Africa (all income levels) 100 | LBR,SSF,Sub-Saharan Africa (all income levels) 101 | LBY,MEA,Middle East & North Africa (all income levels) 102 | LTU,ECS,Europe & Central Asia (all income levels) 103 | LUX,ECS,Europe & Central Asia (all income levels) 104 | MAC,EAS,East Asia & Pacific (all income levels) 105 | MKD,ECS,Europe & Central Asia (all income levels) 106 | MDG,SSF,Sub-Saharan Africa (all income levels) 107 | MWI,SSF,Sub-Saharan Africa (all income levels) 108 | MYS,EAS,East Asia & Pacific (all income levels) 109 | MDV,SAS,South Asia 110 | MLI,SSF,Sub-Saharan Africa (all income levels) 111 | MLT,MEA,Middle East & North Africa (all income levels) 112 | MRT,SSF,Sub-Saharan Africa (all income levels) 113 | MUS,SSF,Sub-Saharan Africa (all income levels) 114 | MYT,SSF,Sub-Saharan Africa (all income levels) 115 | MEX,LCN,Latin America & Caribbean (all income levels) 116 | FSM,EAS,East Asia & Pacific (all income levels) 117 | MDA,ECS,Europe & Central Asia (all income levels) 118 | MNG,EAS,East Asia & Pacific (all income levels) 119 | MNE,ECS,Europe & Central Asia (all income levels) 120 | MAR,MEA,Middle East & North Africa (all income levels) 121 | MOZ,SSF,Sub-Saharan Africa (all income levels) 122 | MMR,EAS,East Asia & Pacific (all income levels) 123 | NAM,SSF,Sub-Saharan Africa (all income levels) 124 | NPL,SAS,South Asia 125 | NLD,ECS,Europe & Central Asia (all income levels) 126 | NCL,EAS,East Asia & Pacific (all income levels) 127 | NZL,EAS,East Asia & Pacific (all income levels) 128 | NIC,LCN,Latin America & Caribbean (all income levels) 129 | NER,SSF,Sub-Saharan Africa (all income levels) 130 | NGA,SSF,Sub-Saharan Africa (all income levels) 131 | NOR,ECS,Europe & Central Asia (all income levels) 132 | OMN,MEA,Middle East & North Africa (all income levels) 133 | PAK,SAS,South Asia 134 | PAN,LCN,Latin America & Caribbean (all income levels) 135 | PNG,EAS,East Asia & Pacific (all income levels) 136 | PRY,LCN,Latin America & Caribbean (all income levels) 137 | PER,LCN,Latin America & Caribbean (all income levels) 138 | PHL,EAS,East Asia & Pacific (all income levels) 139 | POL,ECS,Europe & Central Asia (all income levels) 140 | PRT,ECS,Europe & Central Asia (all income levels) 141 | PRI,LCN,Latin America & Caribbean (all income levels) 142 | QAT,MEA,Middle East & North Africa (all income levels) 143 | ROU,ECS,Europe & Central Asia (all income levels) 144 | RUS,ECS,Europe & Central Asia (all income levels) 145 | RWA,SSF,Sub-Saharan Africa (all income levels) 146 | WSM,EAS,East Asia & Pacific (all income levels) 147 | SMR,ECS,Europe & Central Asia (all income levels) 148 | STP,SSF,Sub-Saharan Africa (all income levels) 149 | SAU,MEA,Middle East & North Africa (all income levels) 150 | SEN,SSF,Sub-Saharan Africa (all income levels) 151 | SRB,ECS,Europe & Central Asia (all income levels) 152 | SYC,SSF,Sub-Saharan Africa (all income levels) 153 | SLE,SSF,Sub-Saharan Africa (all income levels) 154 | SGP,EAS,East Asia & Pacific (all income levels) 155 | SVK,ECS,Europe & Central Asia (all income levels) 156 | SVN,ECS,Europe & Central Asia (all income levels) 157 | SLB,EAS,East Asia & Pacific (all income levels) 158 | SOM,SSF,Sub-Saharan Africa (all income levels) 159 | ZAF,SSF,Sub-Saharan Africa (all income levels) 160 | ESP,ECS,Europe & Central Asia (all income levels) 161 | LKA,SAS,South Asia 162 | LCA,LCN,Latin America & Caribbean (all income levels) 163 | VCT,LCN,Latin America & Caribbean (all income levels) 164 | SDN,SSF,Sub-Saharan Africa (all income levels) 165 | SUR,LCN,Latin America & Caribbean (all income levels) 166 | SWZ,SSF,Sub-Saharan Africa (all income levels) 167 | SWE,ECS,Europe & Central Asia (all income levels) 168 | CHE,ECS,Europe & Central Asia (all income levels) 169 | SYR,MEA,Middle East & North Africa (all income levels) 170 | TJK,ECS,Europe & Central Asia (all income levels) 171 | TZA,SSF,Sub-Saharan Africa (all income levels) 172 | THA,EAS,East Asia & Pacific (all income levels) 173 | TLS,EAS,East Asia & Pacific (all income levels) 174 | TGO,SSF,Sub-Saharan Africa (all income levels) 175 | TON,EAS,East Asia & Pacific (all income levels) 176 | TTO,LCN,Latin America & Caribbean (all income levels) 177 | TUN,MEA,Middle East & North Africa (all income levels) 178 | TUR,ECS,Europe & Central Asia (all income levels) 179 | TKM,ECS,Europe & Central Asia (all income levels) 180 | UGA,SSF,Sub-Saharan Africa (all income levels) 181 | UKR,ECS,Europe & Central Asia (all income levels) 182 | ARE,MEA,Middle East & North Africa (all income levels) 183 | GBR,ECS,Europe & Central Asia (all income levels) 184 | USA,NAC,North America 185 | URY,LCN,Latin America & Caribbean (all income levels) 186 | UZB,ECS,Europe & Central Asia (all income levels) 187 | VUT,EAS,East Asia & Pacific (all income levels) 188 | VEN,LCN,Latin America & Caribbean (all income levels) 189 | VNM,EAS,East Asia & Pacific (all income levels) 190 | VIR,LCN,Latin America & Caribbean (all income levels) 191 | PSE,MEA,Middle East & North Africa (all income levels) 192 | YEM,MEA,Middle East & North Africa (all income levels) 193 | ZMB,SSF,Sub-Saharan Africa (all income levels) 194 | ZWE,SSF,Sub-Saharan Africa (all income levels) 195 | -------------------------------------------------------------------------------- /Line_Charts/line-making.R: -------------------------------------------------------------------------------- 1 | ##### 2 | # 3 | # How to Make a Line Graph 4 | # 5 | ##### 6 | 7 | 8 | # 9 | # Load data 10 | # 11 | 12 | life <- read.csv("data/life-expectancy-cleaned.csv", stringsAsFactors=FALSE) 13 | 14 | #install.packages("reshape") 15 | library(reshape) 16 | life2 <- melt(life, id=c("Country.Name", "Country.Code")) 17 | 18 | 19 | # 20 | # Default line plot 21 | # 22 | 23 | usa <- subset(life2, Country.Code == "USA") 24 | usa <- usa[order(usa$variable, decreasing=FALSE),] 25 | plot(usa$value, type="l") 26 | 27 | 28 | # 29 | # Quick changes 30 | # 31 | 32 | # Dots and lines 33 | plot(usa$value, type="b", cex=0.8) 34 | 35 | # Add x-value (years) 36 | plot(1960:2009, usa$value, type="l", main="USA Life Expectancy, 1960 to 2009", ylab="Years from birth", xlab="", las=1, col="blue", lwd=2, cex.axis=0.8) 37 | 38 | 39 | # 40 | # Multiple lines 41 | # 42 | 43 | # Default (Nope.) 44 | plot(life2[,c(-1,-2)], type="l", main="Life Expectancy, 1960 to 2009", ylab="Years from birth", xlab="") 45 | 46 | # Try that again 47 | plot(0, 0, type="n", xlim=c(1960, 2009), ylim=c(25, 80), main="Life Expectancy, 1960 to 2009", ylab="Years from birth", xlab="", las=1, lwd=2, bty="n", cex.axis=0.7) 48 | codes <- unique(life2$Country.Code) 49 | for (i in 1:length(codes)) { 50 | currCountry <- subset(life2, Country.Code == codes[i]) 51 | currCountry <- currCountry[order(currCountry$variable, decreasing=FALSE),] 52 | # lines(1960:2009, currCountry$value) 53 | lines(1960:2009, currCountry$value, col="#002000") 54 | } 55 | 56 | 57 | # Multiple plots 58 | countries <- read.csv("data/country-regions.csv", stringsAsFactors=FALSE) 59 | life3 <- merge(life2, countries[,c("CountryCode", "RegionName")], by.x="Country.Code", by.y="CountryCode") 60 | regions <- unique(life3$RegionName) 61 | par(mfrow=c(3,3)) 62 | for (i in 1:length(regions)) { 63 | currRegion <- subset(life3, RegionName == regions[i]) 64 | 65 | # Draw plot for region 66 | plot(0, 0, type="n", xlim=c(1960, 2009), ylim=c(25, 80), main=regions[i], ylab="Years from birth", xlab="") 67 | codes <- unique(currRegion$Country.Code) 68 | for (j in 1:length(codes)) { 69 | currCountry <- subset(currRegion, Country.Code == codes[j]) 70 | currCountry <- currCountry[order(currCountry$variable, decreasing=FALSE),] 71 | lines(1960:2009, currCountry$value, col="#002000") 72 | } 73 | } 74 | 75 | 76 | 77 | 78 | 79 | # 80 | # Adjust 81 | # 82 | 83 | 84 | # Line width + Transparency + Grid lines 85 | regionName <- "Sub-Saharan Africa (all income levels)" 86 | currRegion <- subset(life3, RegionName == regionName) 87 | plot(0, 0, type="n", xlim=c(1960, 2009), ylim=c(23, 80), main=regionName, ylab="Years from birth", xlab="", las=1, lwd=2, bty="n", cex.axis=0.8) 88 | grid(NA, NULL, lwd=1.2) 89 | codes <- unique(currRegion$Country.Code) 90 | for (j in 1:length(codes)) { 91 | currCountry <- subset(currRegion, Country.Code == codes[j]) 92 | currCountry <- currCountry[order(currCountry$variable, decreasing=FALSE),] 93 | lines(1960:2009, currCountry$value, col="#00200070", lwd=0.8) 94 | } 95 | 96 | # Make Rwanda line more obvious 97 | currCountry <- subset(currRegion, Country.Code == "RWA") 98 | currCountry <- currCountry[order(currCountry$variable, decreasing=FALSE),] 99 | lines(1960:2009, currCountry$value, col="#402000", lwd=2) 100 | 101 | # Annotate 102 | text(1993 + 0.9, min(currCountry$value)-0.4, "In 1993, Rwanda's average life\nexpectancy was 25 years.", cex=0.85, font=3, pos=4) 103 | symbols(1993, min(currCountry$value), circles=0.5, inches=FALSE, add=TRUE, lwd=2) 104 | 105 | 106 | # Line type 107 | plot(0, 0, type="n", xlim=c(1960, 2009), ylim=c(23, 80), main="Life Expectancy", ylab="Years from birth", xlab="", las=1, lwd=2, bty="n", cex.axis=0.8) 108 | text(1960, 44, "Rwanda", pos=4) 109 | lines(1960:2009, currCountry$value, col="#000000", lwd=2, lty=2) 110 | text(1960, 69, "United States", pos=4) 111 | lines(1960:2009, usa$value, col="#000000", lwd=2, lty=3) 112 | 113 | 114 | # Line types for reference 115 | par(mar=c(0,0,0,0)) 116 | plot(0, 0, xlim=c(0,1), ylim=c(-1,6), type="n", axes=FALSE) 117 | for (i in 1:6) { 118 | lines(c(0,1), c(6-i,6-i), lty=i) 119 | text(0, 6-i+0.2, paste("Line type: ", i, sep=""), pos=4, cex=0.8, font=2) 120 | } 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /Moving_Past_Default_R_Charts/data/country-regions.csv: -------------------------------------------------------------------------------- 1 | CountryCode,RegionCode,RegionName 2 | AFG,SAS,South Asia 3 | ALB,ECS,Europe & Central Asia (all income levels) 4 | DZA,MEA,Middle East & North Africa (all income levels) 5 | AGO,SSF,Sub-Saharan Africa (all income levels) 6 | ARG,LCN,Latin America & Caribbean (all income levels) 7 | ARM,ECS,Europe & Central Asia (all income levels) 8 | ABW,LCN,Latin America & Caribbean (all income levels) 9 | AUS,EAS,East Asia & Pacific (all income levels) 10 | AUT,ECS,Europe & Central Asia (all income levels) 11 | AZE,ECS,Europe & Central Asia (all income levels) 12 | BHS,LCN,Latin America & Caribbean (all income levels) 13 | BHR,MEA,Middle East & North Africa (all income levels) 14 | BGD,SAS,South Asia 15 | BRB,LCN,Latin America & Caribbean (all income levels) 16 | BLR,ECS,Europe & Central Asia (all income levels) 17 | BEL,ECS,Europe & Central Asia (all income levels) 18 | BLZ,LCN,Latin America & Caribbean (all income levels) 19 | BEN,SSF,Sub-Saharan Africa (all income levels) 20 | BTN,SAS,South Asia 21 | BOL,LCN,Latin America & Caribbean (all income levels) 22 | BIH,ECS,Europe & Central Asia (all income levels) 23 | BWA,SSF,Sub-Saharan Africa (all income levels) 24 | BRA,LCN,Latin America & Caribbean (all income levels) 25 | BRN,EAS,East Asia & Pacific (all income levels) 26 | BGR,ECS,Europe & Central Asia (all income levels) 27 | BFA,SSF,Sub-Saharan Africa (all income levels) 28 | BDI,SSF,Sub-Saharan Africa (all income levels) 29 | KHM,EAS,East Asia & Pacific (all income levels) 30 | CMR,SSF,Sub-Saharan Africa (all income levels) 31 | CAN,NAC,North America 32 | CPV,SSF,Sub-Saharan Africa (all income levels) 33 | CAF,SSF,Sub-Saharan Africa (all income levels) 34 | TCD,SSF,Sub-Saharan Africa (all income levels) 35 | CHI,ECS,Europe & Central Asia (all income levels) 36 | CHL,LCN,Latin America & Caribbean (all income levels) 37 | CHN,EAS,East Asia & Pacific (all income levels) 38 | COL,LCN,Latin America & Caribbean (all income levels) 39 | COM,SSF,Sub-Saharan Africa (all income levels) 40 | COD,SSF,Sub-Saharan Africa (all income levels) 41 | COG,SSF,Sub-Saharan Africa (all income levels) 42 | CRI,LCN,Latin America & Caribbean (all income levels) 43 | CIV,SSF,Sub-Saharan Africa (all income levels) 44 | HRV,ECS,Europe & Central Asia (all income levels) 45 | CUB,LCN,Latin America & Caribbean (all income levels) 46 | CYP,ECS,Europe & Central Asia (all income levels) 47 | CZE,ECS,Europe & Central Asia (all income levels) 48 | DNK,ECS,Europe & Central Asia (all income levels) 49 | DJI,MEA,Middle East & North Africa (all income levels) 50 | DOM,LCN,Latin America & Caribbean (all income levels) 51 | ECU,LCN,Latin America & Caribbean (all income levels) 52 | EGY,MEA,Middle East & North Africa (all income levels) 53 | SLV,LCN,Latin America & Caribbean (all income levels) 54 | GNQ,SSF,Sub-Saharan Africa (all income levels) 55 | ERI,SSF,Sub-Saharan Africa (all income levels) 56 | EST,ECS,Europe & Central Asia (all income levels) 57 | ETH,SSF,Sub-Saharan Africa (all income levels) 58 | FJI,EAS,East Asia & Pacific (all income levels) 59 | FIN,ECS,Europe & Central Asia (all income levels) 60 | FRA,ECS,Europe & Central Asia (all income levels) 61 | PYF,EAS,East Asia & Pacific (all income levels) 62 | GAB,SSF,Sub-Saharan Africa (all income levels) 63 | GMB,SSF,Sub-Saharan Africa (all income levels) 64 | GEO,ECS,Europe & Central Asia (all income levels) 65 | DEU,ECS,Europe & Central Asia (all income levels) 66 | GHA,SSF,Sub-Saharan Africa (all income levels) 67 | GRC,ECS,Europe & Central Asia (all income levels) 68 | GRD,LCN,Latin America & Caribbean (all income levels) 69 | GUM,EAS,East Asia & Pacific (all income levels) 70 | GTM,LCN,Latin America & Caribbean (all income levels) 71 | GIN,SSF,Sub-Saharan Africa (all income levels) 72 | GNB,SSF,Sub-Saharan Africa (all income levels) 73 | GUY,LCN,Latin America & Caribbean (all income levels) 74 | HTI,LCN,Latin America & Caribbean (all income levels) 75 | HND,LCN,Latin America & Caribbean (all income levels) 76 | HKG,EAS,East Asia & Pacific (all income levels) 77 | HUN,ECS,Europe & Central Asia (all income levels) 78 | ISL,ECS,Europe & Central Asia (all income levels) 79 | IND,SAS,South Asia 80 | IDN,EAS,East Asia & Pacific (all income levels) 81 | IRN,MEA,Middle East & North Africa (all income levels) 82 | IRQ,MEA,Middle East & North Africa (all income levels) 83 | IRL,ECS,Europe & Central Asia (all income levels) 84 | ISR,MEA,Middle East & North Africa (all income levels) 85 | ITA,ECS,Europe & Central Asia (all income levels) 86 | JAM,LCN,Latin America & Caribbean (all income levels) 87 | JPN,EAS,East Asia & Pacific (all income levels) 88 | JOR,MEA,Middle East & North Africa (all income levels) 89 | KAZ,ECS,Europe & Central Asia (all income levels) 90 | KEN,SSF,Sub-Saharan Africa (all income levels) 91 | PRK,EAS,East Asia & Pacific (all income levels) 92 | KOR,EAS,East Asia & Pacific (all income levels) 93 | KSV,ECS,Europe & Central Asia (all income levels) 94 | KWT,MEA,Middle East & North Africa (all income levels) 95 | KGZ,ECS,Europe & Central Asia (all income levels) 96 | LAO,EAS,East Asia & Pacific (all income levels) 97 | LVA,ECS,Europe & Central Asia (all income levels) 98 | LBN,MEA,Middle East & North Africa (all income levels) 99 | LSO,SSF,Sub-Saharan Africa (all income levels) 100 | LBR,SSF,Sub-Saharan Africa (all income levels) 101 | LBY,MEA,Middle East & North Africa (all income levels) 102 | LTU,ECS,Europe & Central Asia (all income levels) 103 | LUX,ECS,Europe & Central Asia (all income levels) 104 | MAC,EAS,East Asia & Pacific (all income levels) 105 | MKD,ECS,Europe & Central Asia (all income levels) 106 | MDG,SSF,Sub-Saharan Africa (all income levels) 107 | MWI,SSF,Sub-Saharan Africa (all income levels) 108 | MYS,EAS,East Asia & Pacific (all income levels) 109 | MDV,SAS,South Asia 110 | MLI,SSF,Sub-Saharan Africa (all income levels) 111 | MLT,MEA,Middle East & North Africa (all income levels) 112 | MRT,SSF,Sub-Saharan Africa (all income levels) 113 | MUS,SSF,Sub-Saharan Africa (all income levels) 114 | MYT,SSF,Sub-Saharan Africa (all income levels) 115 | MEX,LCN,Latin America & Caribbean (all income levels) 116 | FSM,EAS,East Asia & Pacific (all income levels) 117 | MDA,ECS,Europe & Central Asia (all income levels) 118 | MNG,EAS,East Asia & Pacific (all income levels) 119 | MNE,ECS,Europe & Central Asia (all income levels) 120 | MAR,MEA,Middle East & North Africa (all income levels) 121 | MOZ,SSF,Sub-Saharan Africa (all income levels) 122 | MMR,EAS,East Asia & Pacific (all income levels) 123 | NAM,SSF,Sub-Saharan Africa (all income levels) 124 | NPL,SAS,South Asia 125 | NLD,ECS,Europe & Central Asia (all income levels) 126 | NCL,EAS,East Asia & Pacific (all income levels) 127 | NZL,EAS,East Asia & Pacific (all income levels) 128 | NIC,LCN,Latin America & Caribbean (all income levels) 129 | NER,SSF,Sub-Saharan Africa (all income levels) 130 | NGA,SSF,Sub-Saharan Africa (all income levels) 131 | NOR,ECS,Europe & Central Asia (all income levels) 132 | OMN,MEA,Middle East & North Africa (all income levels) 133 | PAK,SAS,South Asia 134 | PAN,LCN,Latin America & Caribbean (all income levels) 135 | PNG,EAS,East Asia & Pacific (all income levels) 136 | PRY,LCN,Latin America & Caribbean (all income levels) 137 | PER,LCN,Latin America & Caribbean (all income levels) 138 | PHL,EAS,East Asia & Pacific (all income levels) 139 | POL,ECS,Europe & Central Asia (all income levels) 140 | PRT,ECS,Europe & Central Asia (all income levels) 141 | PRI,LCN,Latin America & Caribbean (all income levels) 142 | QAT,MEA,Middle East & North Africa (all income levels) 143 | ROU,ECS,Europe & Central Asia (all income levels) 144 | RUS,ECS,Europe & Central Asia (all income levels) 145 | RWA,SSF,Sub-Saharan Africa (all income levels) 146 | WSM,EAS,East Asia & Pacific (all income levels) 147 | SMR,ECS,Europe & Central Asia (all income levels) 148 | STP,SSF,Sub-Saharan Africa (all income levels) 149 | SAU,MEA,Middle East & North Africa (all income levels) 150 | SEN,SSF,Sub-Saharan Africa (all income levels) 151 | SRB,ECS,Europe & Central Asia (all income levels) 152 | SYC,SSF,Sub-Saharan Africa (all income levels) 153 | SLE,SSF,Sub-Saharan Africa (all income levels) 154 | SGP,EAS,East Asia & Pacific (all income levels) 155 | SVK,ECS,Europe & Central Asia (all income levels) 156 | SVN,ECS,Europe & Central Asia (all income levels) 157 | SLB,EAS,East Asia & Pacific (all income levels) 158 | SOM,SSF,Sub-Saharan Africa (all income levels) 159 | ZAF,SSF,Sub-Saharan Africa (all income levels) 160 | ESP,ECS,Europe & Central Asia (all income levels) 161 | LKA,SAS,South Asia 162 | LCA,LCN,Latin America & Caribbean (all income levels) 163 | VCT,LCN,Latin America & Caribbean (all income levels) 164 | SDN,SSF,Sub-Saharan Africa (all income levels) 165 | SUR,LCN,Latin America & Caribbean (all income levels) 166 | SWZ,SSF,Sub-Saharan Africa (all income levels) 167 | SWE,ECS,Europe & Central Asia (all income levels) 168 | CHE,ECS,Europe & Central Asia (all income levels) 169 | SYR,MEA,Middle East & North Africa (all income levels) 170 | TJK,ECS,Europe & Central Asia (all income levels) 171 | TZA,SSF,Sub-Saharan Africa (all income levels) 172 | THA,EAS,East Asia & Pacific (all income levels) 173 | TLS,EAS,East Asia & Pacific (all income levels) 174 | TGO,SSF,Sub-Saharan Africa (all income levels) 175 | TON,EAS,East Asia & Pacific (all income levels) 176 | TTO,LCN,Latin America & Caribbean (all income levels) 177 | TUN,MEA,Middle East & North Africa (all income levels) 178 | TUR,ECS,Europe & Central Asia (all income levels) 179 | TKM,ECS,Europe & Central Asia (all income levels) 180 | UGA,SSF,Sub-Saharan Africa (all income levels) 181 | UKR,ECS,Europe & Central Asia (all income levels) 182 | ARE,MEA,Middle East & North Africa (all income levels) 183 | GBR,ECS,Europe & Central Asia (all income levels) 184 | USA,NAC,North America 185 | URY,LCN,Latin America & Caribbean (all income levels) 186 | UZB,ECS,Europe & Central Asia (all income levels) 187 | VUT,EAS,East Asia & Pacific (all income levels) 188 | VEN,LCN,Latin America & Caribbean (all income levels) 189 | VNM,EAS,East Asia & Pacific (all income levels) 190 | VIR,LCN,Latin America & Caribbean (all income levels) 191 | PSE,MEA,Middle East & North Africa (all income levels) 192 | YEM,MEA,Middle East & North Africa (all income levels) 193 | ZMB,SSF,Sub-Saharan Africa (all income levels) 194 | ZWE,SSF,Sub-Saharan Africa (all income levels) 195 | -------------------------------------------------------------------------------- /Moving_Past_Default_R_Charts/style-with-base.R: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # Style charts with base R 4 | # 5 | # 6 | 7 | startYear <- 1960; endYear <- 2009 8 | 9 | 10 | # 11 | # Load the data 12 | # 13 | 14 | life <- read.csv("data/life-expectancy-cleaned.csv", stringsAsFactors=FALSE) 15 | countryRegions <- read.csv("data/country-regions.csv", stringsAsFactors=FALSE) 16 | lifeComp <- na.omit(life) 17 | lifeReg <- merge(lifeComp, countryRegions, by.x="Country.Code", by.y="CountryCode") 18 | 19 | # Subset East Asia and Pacific, for sake of simplicity 20 | eap <- subset(lifeReg, RegionName == "East Asia & Pacific (all income levels)") 21 | minVal <- min(eap[,-c(1,2,53,54)]) 22 | maxVal <- max(eap[,-c(1,2,53,54)]) 23 | eapYears <- eap[,-c(1,2,53,54)] 24 | 25 | 26 | # 27 | # Helper function to draw a line for each country 28 | # 29 | lifeLines <- function(series, col="black", hcol="black", lwd=1, hlwd=2, showPoints=FALSE) { 30 | for (i in 1:length(series[,1])) { 31 | lines(startYear:endYear, series[i,], col=col, lwd=lwd) 32 | } 33 | randomIndex <- sample(1:length(series[,1]), 1) 34 | lines(startYear:endYear, series[randomIndex,], col=hcol, lwd=hlwd) 35 | 36 | if (showPoints) { 37 | points(startYear:endYear, series[randomIndex,], col=hcol, pch=4) 38 | } 39 | } 40 | 41 | 42 | 43 | # 44 | # Default plot 45 | # 46 | plot(0, 0, xlim=c(startYear, endYear), ylim=c(minVal, maxVal), type="n") 47 | lifeLines(eapYears) 48 | 49 | 50 | # 51 | # Default Plot Options 52 | # 53 | 54 | plot(0, xlim=c(startYear, endYear), ylim=c(minVal, maxVal), type="n", main="Life Expectancy in East Asia and Pacific", sub="Subtitle", xlab="Years", ylab="Age", asp=1/2) 55 | lifeLines(eapYears) 56 | 57 | # 58 | # Simplified 59 | # 60 | 61 | par(las=1) 62 | plot(0, xlim=c(startYear, endYear), ylim=c(minVal, maxVal), type="n", bty="n", main="Life Expectancy in East Asia and Pacific", xlab="", ylab="Age", asp=1/2) 63 | lifeLines(eapYears, col="#cccccc") 64 | 65 | # 66 | # Newspaper 67 | # 68 | 69 | par(mar=c(4, 4, 3, 1), oma=c(0,0,0,0), xpd=FALSE, xaxs="r", yaxs="i", mgp=c(2.1,.6,0), las=1, lend=1) 70 | plot(0, xlim=c(startYear, endYear), ylim=c(minVal, maxVal), type="n", bty="n", las=1, main="Life Expectancy in East Asia and Pacific", xlab="", ylab=expression(bold("Age")), family="Helvetica", cex.axis=0.8, cex.lab=0.8, asp=1/2) 71 | grid(NA, NULL, col="black", lty="dotted", lwd=0.3) 72 | lifeLines(eapYears, col="dark grey", lwd=0.7, hlwd=3, hcol="#244A5D") 73 | 74 | 75 | 76 | # 77 | # Feltron 78 | # 79 | 80 | par(bg="#36394A", mar=c(5, 4, 3, 2), oma=c(0,0,0,0), xpd=FALSE, xaxs="r", yaxs="i", mgp=c(2.8,0.3,0.5), col.lab="white", col.axis="white", col.main="white", font.main=1, cex.main=0.8, cex.axis=0.8, cex.lab=0.8, family="Helvetica", lend=1, tck=0) 81 | plot(0, xlim=c(startYear, endYear), ylim=c(minVal, maxVal), type="n", bty="n", las=1, asp=1/2, main="LIFE EXPECTANCY IN EAST ASIA AND PACIFIC", xlab="", ylab="") 82 | lifeLines(eapYears, col="white", lwd=0.35, hcol="#E3DF0C", hlwd=3) 83 | 84 | # Axis change 85 | par(bg="#36394A", mar=c(5, 4, 3, 2), oma=c(0,0,0,0), xpd=FALSE, xaxs="r", yaxs="i", mgp=c(2.8,0.3,0.5), col.lab="white", col.axis="white", col.main="white", font.main=1, cex.main=0.8, cex.axis=0.8, cex.lab=0.8, family="Helvetica", lend=1, tck=0, las=1) 86 | plot(0, xlim=c(startYear, endYear), ylim=c(minVal, maxVal), type="n", bty="n", las=1, asp=1/2, main="LIFE EXPECTANCY IN EAST ASIA AND PACIFIC", xlab="", ylab="", xaxt="n", yaxt="n") 87 | axis(1, tick=FALSE, col.axis="white") 88 | axis(2, tick=FALSE, col.axis="white") 89 | lifeLines(eapYears, col="white", lwd=0.35, hcol="#E3DF0C", hlwd=3) 90 | 91 | 92 | # 93 | # FiveThirtyEight 94 | # 95 | 96 | par(mar=c(3, 4, 3, 2), oma=c(0,0,0,0), bg="#F0F0F0", xpd=FALSE, xaxs="r", yaxs="i", mgp=c(2.1,.3,0), las=1, col.axis="#434343", col.main="#343434", tck=0, lend=1) 97 | plot(0, xlim=c(startYear, endYear), ylim=c(minVal, maxVal), type="n", bty="n", las=1, main="Life Expectancy in East Asia and Pacific", xlab="", ylab="Age", family="Helvetica", cex.main=1.5, cex.axis=0.8, cex.lab=0.8, asp=1/2, xaxt="n", yaxt="n") 98 | grid(NULL, NULL, col="#DEDEDE", lty="solid", lwd=0.9) 99 | axis(1, tick=FALSE, cex.axis=0.9) 100 | axis(2, tick=FALSE, cex.axis=0.9) 101 | lifeLines(eapYears, col="dark grey", lwd=1, hlwd=3, hcol="#008ED4") 102 | 103 | 104 | # 105 | # The Economist 106 | # 107 | 108 | # Red corner rectangle 109 | par(xpd=NA, oma=c(0,0,0,0), mar=c(0,0,0,0), bg="#DCE6EC", xpd=FALSE, xaxs="i", yaxs="i", lend=1) 110 | plot(0, 0, type = "n", bty = "n", xaxt="n", yaxt="n", xlim=c(0,100), ylim=c(0,100)) 111 | rect(0,100,2,94, col="red", border=NA) 112 | 113 | # Actual chart 114 | par(mar=c(4, 3, 3, 2), oma=c(0,0,0,0), xpd=FALSE, xaxs="r", yaxs="i", mgp=c(1.8,.2,0), cex.axis=0.7, cex.lab=0.7, col.lab="black", col.axis="black", col.main="black", tck=0.02, yaxp=c(minVal, maxVal, 2), new=TRUE) 115 | plot(0, xlim=c(startYear, endYear), ylim=c(minVal, maxVal), type="n", bty="n", las=1, main="Life Expectancy in East Asia and Pacific", xlab=expression(italic("Years")), ylab=expression(italic("Age")), family="Helvetica", asp=1/2) 116 | grid(NA, NULL, col="white", lty="solid", lwd=1.5) 117 | lifeLines(eapYears, lwd=1.25, hlwd=2.5, col="#33A5A2", hcol="#244A5D") 118 | 119 | 120 | # 121 | # Tukey 122 | # 123 | 124 | par(las=1, tck=0.02, mgp=c(2.8,0.3,0.5), cex.lab=0.85, cex.axis=0.8, cex.main=0.9) 125 | plot(0, xlim=c(startYear, endYear), ylim=c(minVal, maxVal), type="n", bty="n", main="Life Expectancy in East Asia and Pacific", xlab="", ylab="Age", asp=1/2) 126 | lifeLines(eapYears, col="#cccccc", hlwd=1.2, showPoints=TRUE) 127 | 128 | 129 | # 130 | # Bright on Dark 131 | # 132 | 133 | par(bg="black", las=1, tck=0, mgp=c(2.8,0.3,0), cex.lab=0.85, cex.axis=0.8, cex.main=0.9, col.axis="white", col.main="white", col.lab="white") 134 | plot(0, xlim=c(startYear, endYear), ylim=c(minVal, maxVal), type="n", main="Life Expectancy in East Asia and Pacific", xlab="Year", ylab="Age", asp=1/2) 135 | grid(NULL, NULL, lty="solid", col="white", lwd=0.5) 136 | lifeLines(eapYears, col="#f30baa", lwd=1.2, hcol="green", hlwd=3) 137 | 138 | -------------------------------------------------------------------------------- /Slopegraph/pct-gdp.txt: -------------------------------------------------------------------------------- 1 | country,pct1970,pct1979 2 | Sweden,46.9,57.4 3 | Netherlands,44.0,55.8 4 | Norway,43.5,52.2 5 | Britain,40.7,39.0 6 | France,39.0,43.4 7 | Germany,37.5,42.9 8 | Belgium,35.2,43.2 9 | Canada,35.2,35.8 10 | Finland,34.9,38.2 11 | Italy,30.4,35.7 12 | United States,30.3,32.5 13 | Greece,26.8,30.6 14 | Switzerland,26.5,33.2 15 | Spain,22.5,27.1 16 | Japan,20.7,26.6 17 | -------------------------------------------------------------------------------- /Slopegraph/slopegraph.R: -------------------------------------------------------------------------------- 1 | pctgdp <- read.csv('pct-gdp.txt') 2 | 3 | # 4 | # Parallel coordinates plot (not ideal) 5 | # 6 | library(lattice) 7 | parallelplot(pctgdp) 8 | parallelplot(pctgdp[, c("pct1970", "pct1979")], horizontal.axis=FALSE) 9 | 10 | # 11 | # Standard line chart 12 | # 13 | plot(0, 0, type="n", main="Receipts of Government as Percent of GDP", xlab="", ylab="", xlim=c(1970,1979), ylim=c(20,60)) 14 | for (i in 1:length(pctgdp$country)) { 15 | vals <- pctgdp[i,] 16 | lines(c(1970, 1979), c(vals$pct1970, vals$pct1979)) 17 | } 18 | 19 | # Clean up 20 | plot(0, 0, type="n", main="Receipts of Government\n as Percent of GDP", xlab="", ylab="", xlim=c(1970,1979), ylim=c(20,60), bty="n", las=1) 21 | for (i in 1:length(pctgdp$country)) { 22 | vals <- pctgdp[i,] 23 | lines(c(1970, 1979), c(vals$pct1970, vals$pct1979)) 24 | } 25 | 26 | # Add text 27 | plot(0, 0, type="n", main="Receipts of Government\n as Percent of GDP", xlab="", ylab="", xlim=c(1970,1979), ylim=c(20,60), bty="n", las=1, axes=FALSE) 28 | for (i in 1:length(pctgdp$country)) { 29 | vals <- pctgdp[i,] 30 | 31 | # Draw the line for current country 32 | lines(c(1970, 1979), c(vals$pct1970, vals$pct1979)) 33 | 34 | # Left label 35 | text(1970, vals$pct1970, vals$pct1970) 36 | 37 | # Right label 38 | text(1979, vals$pct1979, vals$pct1979) 39 | } 40 | 41 | # 42 | # Clean up text and add more labels 43 | # 44 | par(family="serif") 45 | plot(0, 0, type="n", main="", xlab="", ylab="", xlim=c(1950,1990), ylim=c(20,60), bty="n", las=1, axes=FALSE) 46 | for (i in 1:length(pctgdp$country)) { 47 | vals <- pctgdp[i,] 48 | 49 | # Draw the line for current country 50 | lines(c(1970, 1979), c(vals$pct1970, vals$pct1979)) 51 | 52 | # Left label 53 | text(1970, vals$pct1970, vals$pct1970, pos=2, cex=0.8) 54 | text(1968, vals$pct1970, vals$country, pos=2, cex=0.8) 55 | 56 | # Right label 57 | text(1979, vals$pct1979, vals$pct1979, pos=4, cex=0.8) 58 | text(1981, vals$pct1979, vals$country, pos=4, cex=0.8) 59 | } 60 | 61 | # Title 62 | text(1950, 55, "Current Receipts of Government as a\nPercentage of Gross Domestic\nProduct, 1970 and 1979", cex=0.9, pos=4, family="Helvetica") 63 | 64 | # Year labels 65 | text(1970, 60, "1970", cex=0.9, pos=2, offset=1) 66 | text(1979, 60, "1979", cex=0.9, pos=4, offset=0.5) 67 | 68 | 69 | 70 | # Find out available typefaces 71 | names(pdfFonts()) 72 | 73 | 74 | # 75 | # Sans for loop, same output as above 76 | # 77 | par(family="serif", mar=c(0,0,0,0)) 78 | plot(0, 0, type="n", main="", xlab="", ylab="", xlim=c(1950,1990), ylim=c(20,60), bty="n", las=1, axes=FALSE) 79 | segments(rep(1970, length(pctgdp$country)), pctgdp$pct1970, rep(1979, length(pctgdp$country)), pctgdp$pct1979) 80 | text(rep(1970, length(pctgdp$country)), pctgdp$pct1970, pctgdp$pct1970, pos=2, cex=0.8) 81 | text(rep(1968, length(pctgdp$country)), pctgdp$pct1970, pctgdp$country, pos=2, cex=0.8) 82 | text(rep(1979, length(pctgdp$country)), pctgdp$pct1979, pctgdp$pct1979, pos=4, cex=0.8) 83 | text(rep(1981, length(pctgdp$country)), pctgdp$pct1979, pctgdp$country, pos=4, cex=0.8) 84 | 85 | # Title 86 | text(1950, 55, "Current Receipts of Government as a\nPercentage of Gross Domestic\nProduct, 1970 and 1979", cex=0.9, pos=4, family="Helvetica") 87 | 88 | # Year labels 89 | text(1970, 60, "1970", cex=0.9, pos=2, offset=1) 90 | text(1979, 60, "1979", cex=0.9, pos=4, offset=0.5) 91 | 92 | 93 | 94 | # 95 | # Fix positioning, calculate slope 96 | # 97 | x0 <- c() 98 | y0 <- c() 99 | x1 <- c() 100 | y1 <- c() 101 | 102 | startyear <- 1970 103 | stopyear <- 1979 104 | xoffset <- 2 105 | yoffset <- 0 106 | ystartprev <- 0 107 | ystopprev <- 0 108 | ythreshold <- ( max(pctgdp$pct1970) - min(pctgdp$pct1970) ) * 0.025 109 | for (i in length(pctgdp$country):1) { 110 | vals <- pctgdp[i,] 111 | 112 | ystartdiff <- (vals$pct1970+yoffset) - ystartprev 113 | if (abs(ystartdiff) < ythreshold) { 114 | yoffset <- yoffset + (ythreshold-ystartdiff) 115 | } 116 | 117 | # Calculate slope 118 | slope <- (vals$pct1979 - vals$pct1970) / (stopyear - startyear) 119 | 120 | # Intercept 121 | intercept <- vals$pct1970 + yoffset 122 | 123 | # Start and stop coordinates for lines 124 | ystart <- intercept 125 | ystop <- slope * (stopyear-startyear) + intercept 126 | ystopdiff <- ystop - ystopprev 127 | if (abs(ystopdiff) < ythreshold) { 128 | yoffset <- yoffset + (ythreshold-ystopdiff) 129 | intercept <- vals$pct1970 + yoffset 130 | ystart <- intercept 131 | ystop <- slope * (stopyear-startyear) + intercept 132 | } 133 | 134 | # Draw the line for current country 135 | x0 <- c(x0, startyear) 136 | y0 <- c(y0, ystart) 137 | x1 <- c(x1, stopyear) 138 | y1 <- c(y1, ystop) 139 | 140 | 141 | ystartprev <- ystart 142 | ystopprev <- ystop 143 | } 144 | 145 | ymin <- min(pctgdp$pct1970) 146 | ymax <- max(c(pctgdp$pct1970, pctgdp$pct1979)) + yoffset 147 | 148 | par(family="serif", mar=c(0,0,0,0)) 149 | plot(0, 0, type="n", main="", xlab="", ylab="", xlim=c(1950,1990), ylim=c(ymin,ymax*1.1), bty="n", las=1, axes=FALSE) 150 | segments(x0, y0, x1, y1) 151 | text(x0, y0, rev(pctgdp$pct1970), pos=2, cex=0.6) 152 | text(x0-xoffset, y0, rev(pctgdp$country), pos=2, cex=0.6) 153 | text(x1, y1, rev(pctgdp$pct1979), pos=4, cex=0.6) 154 | text(x1+xoffset, y1, rev(pctgdp$country), pos=4, cex=0.6) 155 | 156 | # Title 157 | text(1950, ymax*1.06, "Current Receipts of\nGovernment as a Percentage\nof Gross Domestic Product,\n1970 and 1979", cex=0.8, pos=4) 158 | 159 | # Year labels 160 | text(startyear, ymax*1.1, "1970", cex=0.7, pos=2, offset=1) 161 | text(stopyear, ymax*1.1, "1979", cex=0.7, pos=4, offset=0.5) 162 | 163 | 164 | 165 | # 166 | # Make it a function for easier usage 167 | # 168 | slopegraph <- function(startpts, endpts, labels) { 169 | 170 | x0 <- c() 171 | y0 <- c() 172 | x1 <- c() 173 | y1 <- c() 174 | 175 | startyear <- 1970 176 | stopyear <- 1979 177 | xoffset <- 2 178 | yoffset <- 0 179 | ystartprev <- 0 180 | ystopprev <- 0 181 | ythreshold <- ( max(startpts) - min(startpts) ) * 0.025 182 | 183 | for (i in length(startpts):1) { 184 | 185 | ystartdiff <- (startpts[i]+yoffset) - ystartprev 186 | if (abs(ystartdiff) < ythreshold) { 187 | yoffset <- yoffset + (ythreshold-ystartdiff) 188 | } 189 | 190 | # Calculate slope 191 | slope <- (endpts[i] - startpts[i]) / (stopyear - startyear) 192 | 193 | # Intercept 194 | intercept <- startpts[i] + yoffset 195 | 196 | # Start and stop coordinates for lines 197 | ystart <- intercept 198 | ystop <- slope * (stopyear-startyear) + intercept 199 | ystopdiff <- ystop - ystopprev 200 | if (abs(ystopdiff) < ythreshold) { 201 | yoffset <- yoffset + (ythreshold-ystopdiff) 202 | intercept <- startpts[i] + yoffset 203 | ystart <- intercept 204 | ystop <- slope * (stopyear-startyear) + intercept 205 | } 206 | 207 | # Draw the line for current country 208 | x0 <- c(x0, startyear) 209 | y0 <- c(y0, ystart) 210 | x1 <- c(x1, stopyear) 211 | y1 <- c(y1, ystop) 212 | 213 | 214 | ystartprev <- ystart 215 | ystopprev <- ystop 216 | } 217 | 218 | ymin <- min(startpts) 219 | ymax <- max(c(startpts, endpts)) + yoffset 220 | 221 | par(family="serif", mar=c(0,0,0,0)) 222 | plot(0, 0, type="n", main="", xlab="", ylab="", xlim=c(1950,1990), ylim=c(ymin,ymax*1.1), bty="n", las=1, axes=FALSE) 223 | segments(x0, y0, x1, y1) 224 | text(x0, y0, rev(startpts), pos=2, cex=0.6) 225 | text(x0-xoffset, y0, rev(labels), pos=2, cex=0.6) 226 | text(x1, y1, rev(endpts), pos=4, cex=0.6) 227 | text(x1+xoffset, y1, rev(labels), pos=4, cex=0.6) 228 | 229 | # Year labels 230 | text(startyear, ymax*1.1, deparse(substitute(startpts)), cex=0.7, pos=2, offset=1) 231 | text(stopyear, ymax*1.1, deparse(substitute(endpts)), cex=0.7, pos=4, offset=0.5) 232 | } 233 | 234 | 235 | -------------------------------------------------------------------------------- /Small_Multiples/areagraph.R: -------------------------------------------------------------------------------- 1 | # Type 0: stacked area, 1: themeriver, 2: streamgraph 2 | areaGraph <- function(thedata, type=2, smooth=TRUE) { 3 | 4 | # Color palette 5 | nColors <- 10 6 | pal <- colorRampPalette(c("#0f7fb4", "#e2e2e2")) 7 | colors <- pal(nColors) 8 | 9 | # Sort the data 10 | if (type == 0) { # Stacked area 11 | 12 | # Greatest to least weights 13 | sortedData <- thedata[order(rowSums(thedata), decreasing=TRUE),] 14 | 15 | } else if (type ==1 || type == 2) { # Themeriver or streamgraph 16 | 17 | # Initialize sorted data frame 18 | sortedData <- thedata[1,] 19 | weights <- rowSums(thedata) 20 | topWeight <- weights[1] 21 | bottomWeight <- weights[1] 22 | 23 | if (length(thedata[,1]) > 1) { 24 | 25 | # Commence sorting. Apparently not most efficient way, but whatever. 26 | for (i in 2:length(thedata[,1])) { 27 | 28 | if (topWeight > bottomWeight) { 29 | sortedData <- rbind(sortedData, thedata[i,]) 30 | } else { 31 | sortedData <- rbind(thedata[i,], sortedData) 32 | bototmWeight <- bottomWeight + weights[i] 33 | } 34 | } 35 | } 36 | 37 | } 38 | 39 | # Smooth the data 40 | if (smooth) { 41 | 42 | nPoints <- 200 43 | 44 | # Initialize smoothed data. Note: Probably a better way to do this, but it works. [NY] 45 | firstRow <- spline(1:length(sortedData[1,]), sortedData[1,], nPoints)$y 46 | firstRow <- sapply(firstRow, zeroNegatives) 47 | 48 | smoothData <- data.frame( rbind(firstRow, rep(0, length(firstRow))) ) 49 | smoothData <- smoothData[1,] 50 | 51 | # Smooth the rest of the data using spline(). 52 | if (length(sortedData[,1]) > 1) { 53 | 54 | for (i in 2:length(sortedData[,1])) { 55 | newRow <- spline(1:length(sortedData[i,]), sortedData[i,], nPoints)$y 56 | newRow <- sapply(newRow, zeroNegatives) 57 | smoothData <- rbind(smoothData, newRow) 58 | } 59 | } 60 | 61 | finalData <- smoothData 62 | 63 | } else { 64 | 65 | finalData <- sortedData 66 | 67 | } 68 | 69 | # Totals for each vertical slice 70 | totals <- colSums(finalData) 71 | 72 | # Determine baseline offset 73 | if (type == 0) { 74 | 75 | yOffset <- rep(0, length(totals)) 76 | 77 | } else if (type == 1) { 78 | 79 | yOffset <- -totals / 2 80 | 81 | } else if (type == 2) { 82 | n <- length(finalData[,1]) 83 | i <- 1:length(finalData[,1]) 84 | parts <- (n - i + 1) * finalData 85 | theSums <- colSums(parts) 86 | yOffset <- -theSums / (n + 1) 87 | } 88 | 89 | 90 | # Axis upper and lower bounds 91 | yLower <- min(yOffset) 92 | yUpper <- max(yOffset + totals) 93 | 94 | # Max, min, and span of weights for each layer 95 | maxRow <- max(rowSums(finalData)) 96 | minRow <- min(rowSums(finalData)) 97 | rowSpan <- if ( (maxRow - minRow) > 0 ) { maxRow - minRow } else { 1 } 98 | 99 | # Make the graph. 100 | par(las=1, cex=0.6, bty="n") 101 | plot(0, 0, type="n", xlim=c(1, length(finalData[1,])), ylim=c(yLower, yUpper), xlab=NA, ylab=NA) 102 | for (i in 1:length(finalData[,1])) { 103 | 104 | colIndex <- floor( (nColors-2) * ( (maxRow - sum(finalData[i,])) / rowSpan ) ) + 1 105 | polygon(c(1:length(finalData[i,]), length(finalData[i,]):1), c(finalData[i,] + yOffset, rev(yOffset)), col=colors[colIndex], border="#ffffff", lwd=0.2) 106 | 107 | # Move up to next layer. 108 | yOffset <- yOffset + finalData[i,] 109 | } 110 | 111 | } 112 | 113 | 114 | # Helper function to convert negative values to zero 115 | zeroNegatives <- function(x) { 116 | if (x < 0) { return(0) } 117 | else { return(x) } 118 | } -------------------------------------------------------------------------------- /Small_Multiples/data/12s0121-truncated.txt: -------------------------------------------------------------------------------- 1 | Cause of death Under 1 year 1 to 4 years 5 to 14 years 15 to 24 years 25 to 34 years 35 to 44 years 45 to 54 years 55 to 64 years 65 to 74 years 75 to 84 years 85 years and over Certain other intestinal infections 11 14 5 5 15 36 122 325 915 2446 2864 Septicemia 283 78 74 160 297 910 2431 4231 6345 10403 9614 Viral hepatitis 1 1 0 14 72 489 2815 2413 871 570 161 Human immunodeficiency virus (HIV) disease 5 4 10 160 1091 3572 4156 1721 448 109 16 Other and unspecified infectious and parasitic diseases and their sequelae 154 63 51 97 136 229 511 919 1098 1463 1104 "..Malignant neoplasms of lip, oral cavity and pharynx" 0 0 1 18 44 251 1136 2019 1915 1741 942 ..Malignant neoplasm of esophagus 0 0 0 5 28 246 1452 3379 3726 3376 1380 ..Malignant neoplasm of stomach 1 0 0 14 127 456 1151 1879 2555 3255 1950 "..Malignant neoplasms of colon, rectum and anus" 0 0 1 35 275 1302 4793 9058 11634 15417 11069 ..Malignant neoplasms of liver and intrahepatic bile ducts 6 19 25 38 90 368 2503 4181 3884 4266 1766 ..Malignant neoplasm of pancreas 0 0 2 5 52 538 2808 6507 8671 10317 5217 ..Malignant neoplasm of larynx 0 0 0 2 2 55 450 932 989 871 333 "..Malignant neoplasms of trachea, bronchus and lung" 1 1 4 25 135 1852 12480 31216 48157 48358 16528 ..Malignant melanoma of skin 0 1 2 31 175 466 1174 1742 1737 2035 1098 ..Malignant neoplasm of breast 0 0 0 15 344 2184 5990 8756 8179 9075 6426 ..Malignant neoplasm of cervix uteri 0 0 0 8 183 645 915 892 611 506 261 "..Malignant neoplasms of corpus uteri and uterus, part unspecified" 0 0 0 2 31 168 584 1583 2021 1960 1107 ..Malignant neoplasm of ovary 0 0 0 28 79 352 1532 2997 3616 3946 2071 ..Malignant neoplasm of prostate 0 1 0 1 1 21 428 2271 5716 11257 9397 ..Malignant neoplasms of kidney and renal pelvis 2 9 25 34 50 240 1243 2584 3159 3539 1818 ..Malignant neoplasm of bladder 1 0 0 0 7 93 570 1564 2817 5009 3782 "..Malignant neoplasms of meninges, brain and other parts of central nervous system" 15 109 302 204 369 845 1916 2975 3002 2608 889 ....Hodgkin's disease 0 0 3 65 120 135 145 176 209 286 132 ....Non-Hodgkins lymphoma 2 5 33 133 206 516 1392 2922 4476 6868 3975 ....Leukemia 21 106 314 428 438 657 1362 2801 4611 6858 4228 ....Multiple myeloma and immunoproliferative neoplasms 0 0 0 2 7 155 705 1788 2917 3853 1879 ..All other and unspecified malignant neoplasms 20 113 245 558 700 1742 5436 10942 13854 18188 11394 "In situ neoplasms, benign neoplasms and neoplasms of uncertain or unknown behavior" 59 59 84 81 138 340 699 1416 2402 4717 4209 Anemias 17 17 32 90 136 187 255 322 560 1224 1989 Diabetes mellitus 7 5 21 168 610 1984 5753 11304 15112 21189 15227 Nutritional deficiencies 7 5 3 4 19 36 93 201 333 808 1343 Malnutrition 6 2 3 4 18 35 87 188 314 755 1232 Parkinson's disease 0 0 0 2 2 12 60 396 2310 9363 7911 Alzheimer's disease 0 0 0 0 1 8 95 728 3984 23009 46804 ....Acute rheumatic fever and chronic rheumatic heart diseases 2 1 1 12 28 70 177 337 529 1055 989 ....Hypertensive heart disease 1 1 0 44 338 1372 3604 4487 4009 6324 10598 ....Hypertensive heart and renal disease 0 0 0 5 32 77 178 293 379 792 1231 ....Ischemic heart diseases 24 8 21 151 1048 6219 24390 46164 63027 116152 149126 ......Acute myocardial infarction 10 4 11 54 400 2402 9467 17835 23441 37629 41711 ......Other acute ischemic heart diseases 2 0 0 3 17 109 376 679 740 1021 1145 ......Other forms of chronic ischemic heart disease 12 4 10 94 631 3708 14547 27650 38846 77502 106270 "........Atherosclerotic cardiovascular disease, so described" 1 0 0 17 211 1395 5910 10055 9884 14221 17347 ........All other forms of chronic ischemic heart disease 11 4 10 77 420 2313 8637 17595 28962 63281 88923 Other heart diseases 397 163 219 872 1777 4101 9085 14246 21645 46934 73305 ......Acute and subacute endocarditis 3 1 1 9 32 95 198 207 236 308 134 ......Heart failure 21 11 12 43 87 317 1073 2758 5749 15935 30558 ......All other forms of heart disease 348 132 182 772 1605 3602 7698 11158 15541 30554 42497 ..Essential (primary) hypertension and hypertensive 1 1 0 23 85 384 1235 2124 3133 6442 10536 ..Cerebrovascular diseases 132 52 83 195 505 2133 6385 10500 18007 41979 55975 ..Atherosclerosis 1 0 0 2 1 27 134 350 829 2298 4590 ..Other diseases of circulatory system 13 4 14 65 136 484 1092 2296 4065 7074 6694 ....Aortic aneurysm and dissection 1 0 7 38 99 364 752 1483 2616 4346 3279 "....Other diseases of arteries, arterioles and capillaries" 12 4 7 27 37 120 340 813 1449 2728 3415 ..Other disorders of circulatory system 53 3 6 40 120 322 570 586 552 888 960 Influenza and pneumonia 222 109 103 163 331 784 1909 3152 5547 14859 25535 Chronic lower respiratory diseases 43 57 118 149 263 796 4153 12777 28664 48041 32857 Pneumonitis due to solids and liquids 10 8 16 47 70 154 436 884 1724 5187 8451 Other diseases of respiratory system 319 100 66 152 216 493 1376 3038 5556 9535 7657 Peptic ulcer 2 0 2 6 20 78 293 378 487 828 951 Diseases of appendix 1 2 10 16 9 19 40 56 92 110 81 Hernia 35 5 2 2 8 35 98 170 244 474 625 Chronic liver disease and cirrhosis 4 4 0 30 384 2570 8212 8004 5167 3694 1093 ..Alcoholic liver disease 0 0 0 17 293 1834 5126 4309 1959 747 118 ..Other chronic liver disease and cirrhosis 4 4 0 13 91 736 3086 3695 3208 2947 975 Cholelithiasis and other disorders of gallbladder 1 2 1 7 23 54 132 240 482 1011 1284 "Nephritis, nephrotic syndrome and nephrosis" 144 22 24 86 261 754 2233 4440 7752 14711 16021 " specified as acute or chronic, and renal scerosis, unspecified" 1 2 3 8 17 51 126 208 384 928 1230 ..Renal failure 138 16 18 77 237 696 2091 4205 7330 13718 14737 Certain conditions originating in the perinatal period 14466 70 22 17 3 4 5 3 3 1 0 "Congenital malformations, deformations and chromosomal abnormalities" 5785 545 374 402 417 513 685 686 341 406 265 "Symptoms, signs and abnormal clinical and laboratory findings, not elsewhere classified" 3617 237 110 575 877 1424 2195 2229 2499 5834 13860 All other diseases (Residual) 1337 599 876 1957 3149 7068 16499 22895 28838 61153 93813 ..Transport accidents 127 581 1374 10928 7452 6829 7199 4838 3194 2983 1326 ..Motor vehicle accidents 124 551 1285 10568 7087 6370 6530 4359 2940 2845 1277 ..Other land transport accidents 1 19 53 174 134 181 235 123 81 61 18 "....Water, air and space, and other and unspecified transport accidents and their sequelae" 2 11 36 186 231 278 434 356 173 77 31 ..Nontransport accidents 1158 1007 820 4969 7525 10102 13116 7355 5559 10753 14477 ....Falls 24 36 32 233 334 593 1304 1739 2594 6552 9188 ....Accidental drowning and submersion 57 458 224 630 381 417 481 324 194 184 88 "....Accidental exposure to smoke, fire and flames" 38 201 211 194 222 307 488 492 421 436 272 ....Accidental poisoning and exposure to 19 34 81 3159 5700 7575 9006 3120 602 355 192 ....Other and unspecified nontransport accidents and their sequelae 1019 260 226 598 794 1119 1755 1623 1717 3195 4730 Intentional self-harm (suicide) 0 0 184 4140 5278 6722 7778 5069 2444 2119 858 ..Intentional self-harm (suicide) by discharge of firearms 0 0 53 1900 2306 2879 3531 2786 1700 1589 606 ..Intentional self-harm (suicide) by other and unspecified means and their sequelae 0 0 131 2240 2972 3843 4247 2283 744 530 252 Assault (homicide) 352 398 346 5551 4758 3052 2140 980 411 268 80 Events of undetermined intent 88 49 49 579 872 1251 1501 599 183 132 70 Complications of medical and surgical care 22 23 21 30 72 150 250 398 486 712 433 Enterocolitis due to clostridium difficile 4 1 1 4 14 31 107 313 876 2338 2647 -------------------------------------------------------------------------------- /Small_Multiples/data/12s0121-truncated.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plissonf/FlowingData/7a7115de92496cd422714dc353aa0c8a0f76c9f4/Small_Multiples/data/12s0121-truncated.xls -------------------------------------------------------------------------------- /Small_Multiples/data/12s0121.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plissonf/FlowingData/7a7115de92496cd422714dc353aa0c8a0f76c9f4/Small_Multiples/data/12s0121.xls -------------------------------------------------------------------------------- /Small_Multiples/multiples.R: -------------------------------------------------------------------------------- 1 | # Load data 2 | causes <- read.csv("./data/12s0121-truncated.txt", sep="\t", header=TRUE) 3 | 4 | # One bar plot 5 | png("images/00.png", width=625) 6 | i <- 1 7 | firstCause <- causes[i,2:12] 8 | barplot(as.numeric(firstCause)) 9 | dev.off() 10 | 11 | 12 | # Bar plot for each cause 13 | png("images/01.png", width=954) 14 | par(mfrow=c(10,9), mar=c(1,2,1,1)) 15 | for (i in 1:length(causes[,1])) { 16 | currCause <- causes[i,2:12] 17 | barplot(as.numeric(currCause)) 18 | } 19 | dev.off() 20 | 21 | 22 | # Make bar plots more readable. 23 | png("images/02.png", width=954, height=725) 24 | par(mfrow=c(12,8), mar=c(1,5,3,1)) 25 | for (i in 1:length(causes[,1])) { 26 | currCause <- causes[i,2:12] 27 | barplot(as.numeric(currCause), main=causes[i,1], cex.main=0.8, cex.axis=0.7, border="white", space=0) 28 | } 29 | dev.off() 30 | 31 | 32 | # Mess around with axes 33 | png("images/03.png", width=954, height=725) 34 | par(mfrow=c(12,8), mar=c(1,5,3,1)) 35 | for (i in 1:length(causes[,1])) { 36 | currCause <- causes[i,2:12] 37 | 38 | # Draw bar plot with no axes 39 | barplot(as.numeric(currCause), main=causes[i,1], cex.main=0.8, cex.axis=0.7, border="white", col="#e26b43", space=0, axes=FALSE) 40 | 41 | # Draw custom axes 42 | axis(side=1, at=c(0,11), labels=FALSE) 43 | axis(side=2, at=c(0,max(currCause)), cex=0.7) 44 | } 45 | dev.off() 46 | 47 | 48 | # Compare counts 49 | png("images/04.png", width=954, height=725) 50 | par(mfrow=c(12,8), mar=c(1,5,3,1)) 51 | for (i in 1:length(causes[,1])) { 52 | currCause <- causes[i,2:12] 53 | 54 | # Draw bar plot with no axes, same vertical scale 55 | barplot(as.numeric(currCause), main=causes[i,1], cex.main=0.8, cex.axis=0.7, border="white", col="#e26b43", space=0, axes=FALSE, ylim=c(0,120000)) 56 | 57 | # Draw custom axes 58 | axis(side=1, at=c(0,11), labels=FALSE) 59 | axis(side=2, at=c(0,max(currCause)), cex=0.7) 60 | } 61 | dev.off() 62 | 63 | 64 | # Highlighting 65 | png("images/05.png", width=954, height=725) 66 | par(mfrow=c(12,8), mar=c(1,5,3,1)) 67 | for (i in 1:length(causes[,1])) { 68 | currCause <- as.numeric( causes[i,2:12] ) 69 | 70 | # Find age group with highest count 71 | maxCnt <- max(currCause) 72 | groupNum <- which(currCause == maxCnt) 73 | 74 | # Color based on max age group 75 | if (groupNum < 5) { 76 | barColor <- "#e26b43" # Orange-red 77 | } else { 78 | barColor <- "#cccccc" # Gray 79 | } 80 | 81 | # Draw the bar plot 82 | barplot(currCause, main=causes[i,1], cex.main=0.8, cex.axis=0.7, border="white", col=barColor, space=0, axes=FALSE) 83 | axis(side=1, at=c(0,11), labels=FALSE) 84 | axis(side=2, at=c(0,max(currCause)), cex=0.8) 85 | } 86 | dev.off() 87 | 88 | 89 | 90 | # Custom chart (just one) 91 | png("images/06.png", width=625) 92 | i <- 1 93 | firstCause <- as.numeric( causes[i,2:12] ) 94 | maxCnt <- max(firstCause) 95 | yOffset <- (maxCnt - firstCause) / 2 96 | plot(0, 0, type="n", xlim=c(0,11), ylim=c(0, max(firstCause)), xlab="", ylab="", axes=FALSE, bty="n") 97 | rect(0:10, yOffset, 1:11, firstCause+yOffset, col="#cccccc", border="white") 98 | dev.off() 99 | 100 | 101 | # Now do it for all causes 102 | png("images/07.png", width=954, height=725) 103 | par(mfrow=c(12,8), mar=c(1,3,3,1)) 104 | for (i in 1:length(causes[,1])) { 105 | currCause <- as.numeric( causes[i,2:12] ) 106 | 107 | # Find age group with highest count 108 | maxCnt <- max(currCause) 109 | 110 | # Draw the custom chart 111 | yOffset <- (maxCnt - currCause) / 2 112 | plot(0, 0, type="n", xlim=c(0,11), ylim=c(0, max(currCause)), xlab="", ylab="", axes=FALSE, bty="n", cex.main=0.8, main=causes[i,1]) 113 | rect(0:10, yOffset, 1:11, currCause+yOffset, col="#e26b43", border="white") 114 | } 115 | dev.off() 116 | 117 | 118 | # Try a different plot type for kicks 119 | png("images/08.png", width=954, height=850) 120 | par(mfrow=c(12,8), mar=c(1,3,3,1)) 121 | source("areaGraph.R") 122 | for (i in 1:length(causes[,1])) { 123 | currCause <- causes[i,2:12] 124 | areaGraph(currCause) 125 | } 126 | dev.off() 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /Text_display/areagraph.R: -------------------------------------------------------------------------------- 1 | # Type 0: stacked area, 1: themeriver, 2: streamgraph 2 | areaGraph <- function(thedata, type=2, smooth=TRUE) { 3 | 4 | # Color palette 5 | nColors <- 15 6 | # pal <- colorRampPalette(c("#0f7fb4", "#e2e2e2")) 7 | # pal <- colorRampPalette(c("#6364a9", "#e2e2e2")) # Purple 8 | pal <- colorRampPalette(c("#48611d", "#f0f0f0")) 9 | colors <- pal(nColors) 10 | 11 | # Sort the data 12 | if (type == 0) { # Stacked area 13 | 14 | # Greatest to least weights 15 | sortedData <- thedata[order(rowSums(thedata), decreasing=TRUE),] 16 | layerNames <- rownames(sortedData) 17 | 18 | } else if (type == 1 || type == 2) { # Themeriver or streamgraph 19 | 20 | # Initialize sorted data frame 21 | sortedData <- thedata[1,] 22 | weights <- rowSums(thedata) 23 | topWeight <- weights[1] 24 | bottomWeight <- weights[1] 25 | layerNames <- c(rownames(thedata)[1]) 26 | 27 | if (length(thedata[,1]) > 1) { 28 | 29 | # Commence sorting. Apparently not most efficient way, but whatever. 30 | for (i in 2:length(thedata[,1])) { 31 | 32 | if (topWeight > bottomWeight) { 33 | sortedData <- rbind(sortedData, thedata[i,]) 34 | layerNames <- c(layerNames, rownames(thedata)[i]) 35 | } else { 36 | sortedData <- rbind(thedata[i,], sortedData) 37 | bottomWeight <- bottomWeight + weights[i] 38 | layerNames <- c(rownames(thedata)[i], layerNames) 39 | } 40 | } 41 | } 42 | 43 | } 44 | 45 | # Smooth the data 46 | if (smooth) { 47 | 48 | nPoints <- length(thedata[1,]) * 3 49 | 50 | # Initialize smoothed data. Note: Probably a better way to do this, but it works. [NY] 51 | firstRow <- spline(1:length(sortedData[1,]), sortedData[1,], nPoints)$y 52 | firstRow <- sapply(firstRow, zeroNegatives) 53 | 54 | smoothData <- data.frame( rbind(firstRow, rep(0, length(firstRow))) ) 55 | smoothData <- smoothData[1,] 56 | 57 | # Smooth the rest of the data using spline(). 58 | if (length(sortedData[,1]) > 1) { 59 | 60 | for (i in 2:length(sortedData[,1])) { 61 | newRow <- spline(1:length(sortedData[i,]), sortedData[i,], nPoints)$y 62 | newRow <- sapply(newRow, zeroNegatives) 63 | smoothData <- rbind(smoothData, newRow) 64 | } 65 | } 66 | 67 | finalData <- smoothData 68 | 69 | } else { 70 | 71 | finalData <- sortedData 72 | 73 | } 74 | 75 | 76 | # Totals for each vertical slice 77 | totals <- colSums(finalData) 78 | 79 | # Determine baseline offset 80 | if (type == 0) { 81 | 82 | yOffset <- rep(0, length(totals)) 83 | 84 | } else if (type == 1) { 85 | 86 | yOffset <- -totals / 2 87 | 88 | } else if (type == 2) { 89 | n <- length(finalData[,1]) 90 | i <- 1:length(finalData[,1]) 91 | parts <- (n - i + 1) * finalData 92 | theSums <- colSums(parts) 93 | yOffset <- -theSums / (n + 1) 94 | } 95 | 96 | 97 | # Axis upper and lower bounds 98 | yLower <- min(yOffset) 99 | yUpper <- max(yOffset + totals) 100 | 101 | # Max, min, and span of weights for each layer 102 | maxRow <- max(rowSums(finalData)) 103 | minRow <- min(rowSums(finalData)) 104 | rowSpan <- if ( (maxRow - minRow) > 0 ) { maxRow - minRow } else { 1 } 105 | 106 | # Make the graph. 107 | par(las=1, cex=0.6, bty="n") 108 | xtext <- c(); ytext <- c(); textSizes <- c() 109 | 110 | plot(0, 0, type="n", xlim=c(1, length(finalData[1,])), ylim=c(yLower, yUpper), xlab=NA, ylab=NA) 111 | for (i in 1:length(finalData[,1])) { 112 | 113 | colIndex <- floor( (nColors-2) * ( (maxRow - sum(finalData[i,])) / rowSpan ) ) + 1 114 | polygon(c(1:length(finalData[i,]), length(finalData[i,]):1), c(finalData[i,] + yOffset, rev(yOffset)), col=colors[colIndex], border="#ffffff", lwd=0.2) 115 | 116 | 117 | # Label locations 118 | xmax <- which.max(finalData[i,]) 119 | xtext <- c(xtext, xmax) 120 | ytext <- c(ytext, finalData[i,xmax] / 2 + yOffset[xmax]) 121 | textSizes <- c(textSizes, 1.7 * sqrt( (nColors-colIndex) / nColors )) 122 | 123 | # Move up to next layer. 124 | yOffset <- yOffset + finalData[i,] 125 | } 126 | 127 | 128 | # Add labels last. 129 | if (length(layerNames) > 0) { 130 | text(xtext, ytext, layerNames, cex=textSizes) 131 | } 132 | 133 | } 134 | 135 | 136 | # Helper function to convert negative values to zero 137 | zeroNegatives <- function(x) { 138 | if (x < 0) { return(0) } 139 | else { return(x) } 140 | } -------------------------------------------------------------------------------- /Text_display/labels-tutorial.R: -------------------------------------------------------------------------------- 1 | # Hello, world. 2 | plot(0, 0, type="n", xlim=c(0, 2), ylim=c(0, 2), xlab="", ylab="") 3 | text(1, 1, 'Hello, world.') 4 | 5 | # Hello, world. x3 6 | plot(0, 0, type="n", xlim=c(0, 2), ylim=c(0, 2), xlab="", ylab="") 7 | text(1, 1, 'Hello, world.') # Middle 8 | text(1, 2, 'Hello, top of world.') # Top 9 | text(1, 0, 'Hello, bottom of world.') # Bottom 10 | 11 | # Hello, world. x3 in one call 12 | plot(0, 0, type="n", xlim=c(0, 2), ylim=c(0, 2), xlab="", ylab="") 13 | x <- c(1, 1, 1) 14 | y <- c(1, 2, 0) 15 | labels <- c('Hello, world.', 'Hello, top of world.', 'Hello, bottom of world.') 16 | text(x, y, labels) 17 | 18 | # Available font families 19 | names(pdfFonts()) 20 | plot(0, 0, type="n", xlim=c(0, 2), ylim=c(0, 2), xlab="", ylab="") 21 | text(x, y, labels, family='Courier') 22 | text(1, 1.5, 'Helvetica', family='Helvetica') 23 | text(1, 0.5, 'Bookman', family='Palatino') 24 | 25 | # Font size 26 | plot(0, 0, type="n", xlim=c(0, 2), ylim=c(0, 2), xlab="", ylab="") 27 | text(x, y, labels, family='Courier', cex=1.0) 28 | text(1, 1.5, 'Helvetica', family='Helvetica', cex=3.0) 29 | text(1, 0.5, 'Bookman', family='Palatino', cex=0.5) 30 | 31 | # Color 32 | plot(0, 0, type="n", xlim=c(0, 2), ylim=c(0,20), xlab="", ylab="", xaxt="n", yaxt="n", bty="n") 33 | rect(0, 0, 2, 30, col="black") 34 | for (i in 1:40) { 35 | text(1, i/2, colors()[i], col=colors()[i], cex=runif(1, 0.2, 1.3)) 36 | } 37 | 38 | # Put it into practice with real data 39 | load('unisexCnts.RData') 40 | nameTotals <- rowSums(unisexCnts) 41 | plot(0, 0, type="n", xlim=c(-5, 105), ylim=c(-5,105), xlab="", ylab="", xaxt="n", yaxt="n", bty="n") 42 | x <- runif(length(nameTotals), 0, 100) 43 | y <- runif(length(nameTotals), 0, 100) 44 | text(x, y, names(nameTotals), cex=2*sqrt(nameTotals/max(nameTotals))) 45 | 46 | # Supplement the area graph (http://datafl.ws/21a) with labels 47 | source('areagraph.R') 48 | areaGraph(unisexCnts) 49 | 50 | -------------------------------------------------------------------------------- /Text_display/unisexCnts.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plissonf/FlowingData/7a7115de92496cd422714dc353aa0c8a0f76c9f4/Text_display/unisexCnts.RData --------------------------------------------------------------------------------