File:Contribution size.png
Generated using data from Oct 1 2009 - May 31 2010. Unofficial personal work, has not been peer reviewed.
"R" source:
input_file = "rawamount.txt.csv"
subtitle = "(2009 fund season)"
output_format = "ps"
dollar_range_endpoints = c(0, 30, 50, 100, 200, 1000, 1000000)
interval_labels = c("less than $30", "$30 to $50", "$50 to $100", "$100 to $200", "$200 to $1,000", "$1000 and up")
#lab = paste(levels(dollar_range_endpoints), "\n", signif(avgs, 2)),
# t("less than %C") t("%C to %C") t("%C and up")
data_bin <- function(data, breaks)
{
h = hist(data,
breaks = breaks,
plot = FALSE
)
cuts = cut(data,
breaks = h$breaks,
include.lowest = TRUE,
dig.lab = 10
)
out = {}
out$counts = h$counts
#out$medians =
out$avgs = tapply(data, cuts, mean)
out$areas = out$counts * out$avgs
out$portions = out$areas / sum(out$areas)
return(out)
}
start_output_capture = function(label)
{
output_path = paste("./", label, ".", output_format, sep="")
postscript(file = output_path)
}
data = scan(
file = input_file,
skip = 0,
sep = ","
)
start_output_capture("contribution size - pie")
bins = data_bin(data, dollar_range_endpoints)
labels = gettextf(
"%s\n (%d%% of total, mean $%0.2f)",
interval_labels,
round(bins$portions * 100),
signif(bins$avgs, 4)
)
pie(
bins$areas,
lab = labels,
main = paste("Relative contributions to total, by donation size", subtitle),
col = heat.colors(length(bins$avgs))
)
dev.off()