File:Contribution size 2012 - pie.png

From MediaWiki.org
Jump to navigation Jump to search

Contribution_size_2012_-_pie.png(690 × 462 pixels, file size: 35 KB, MIME type: image/png)

Donation distribution spanning July 1st, 2012 - Dec 28, 2012.

pie.sql:

-- mysql -BN civicrm < pie.sql

set @start = "20120701";
set @end = "20121228";

SELECT 10, SUM(total_amount), AVG(total_amount), COUNT(total_amount)
    FROM civicrm_contribution
    WHERE (receive_date BETWEEN @start AND @end) AND total_amount BETWEEN 0 AND 10;
SELECT 30, SUM(total_amount), AVG(total_amount), COUNT(total_amount)
    FROM civicrm_contribution
    WHERE (receive_date BETWEEN @start AND @end) AND total_amount BETWEEN 10 AND 30;
SELECT 50, SUM(total_amount), AVG(total_amount), COUNT(total_amount)
    FROM civicrm_contribution
    WHERE (receive_date BETWEEN @start AND @end) AND total_amount BETWEEN 30 AND 50;
SELECT 100, SUM(total_amount), AVG(total_amount), COUNT(total_amount)
    FROM civicrm_contribution
    WHERE (receive_date BETWEEN @start AND @end) AND total_amount BETWEEN 50 AND 100;
SELECT 200, SUM(total_amount), AVG(total_amount), COUNT(total_amount)
    FROM civicrm_contribution
    WHERE (receive_date BETWEEN @start AND @end) AND total_amount BETWEEN 100 AND 200;
SELECT 1000, SUM(total_amount), AVG(total_amount), COUNT(total_amount)
    FROM civicrm_contribution
    WHERE (receive_date BETWEEN @start AND @end) AND total_amount BETWEEN 200 AND 1000;
SELECT 250000, SUM(total_amount), AVG(total_amount), COUNT(total_amount)
    FROM civicrm_contribution
    WHERE (receive_date BETWEEN @start AND @end) AND total_amount BETWEEN 1000 AND 250000;
SELECT 1000000, SUM(total_amount), AVG(total_amount), COUNT(total_amount)
    FROM civicrm_contribution
    WHERE (receive_date BETWEEN @start AND @end) AND total_amount BETWEEN 250000 AND 1000000;
SELECT -1, SUM(total_amount), AVG(total_amount), COUNT(total_amount)
    FROM civicrm_contribution
    WHERE (receive_date BETWEEN @start AND @end) AND total_amount > 1000000;

pie.R:

# R --no-save < pie.R && ps2pdf "contribution size - pie.ps" && convert "contribution size - pie.pdf" "contribution size 2012 - pie.png"

# tsv, actually, but this suffix helps *office not have a cow
input_file = "splitamounts.csv"

subtitle = "(2012 fund season)"
output_format = "ps"
 
# TODO make from column 1
interval_labels = c("less than $10", "$10 to $30", "$30 to $50", "$50 to $100", "$100 to $200", "$200 to $1,000", "$1,000 to $250,000", "$250,000 to $1M", "$1M and up")
    #lab = paste(levels(dollar_range_endpoints), "\n", signif(avgs, 2)),
    # t("less than %C") t("%C to %C") t("%C and up")
 
start_output_capture = function(label)
{
    output_path = paste("./", label, ".", output_format, sep="")
    postscript(file = output_path)
}
 
 
data = scan(
    file = input_file,
    skip = 0,
    what = list( top=0, sum=0, avgs=0, counts=0 )
)
 
start_output_capture("contribution size - pie")
data$areas = data$counts * data$avgs
data$portions = data$areas / sum(data$areas)
str_means = formatC(
    signif(data$avgs, 4),
    format = "f",
    digits = 2,
    big.mark = ","
)
labels = gettextf(
    "%s\n (%d%% of total, mean $%s)",
    interval_labels,
    round(data$portions * 100),
    str_means
)
pie(
    data$areas,
    lab = labels,
    main = paste("Relative contributions to total, by donation size", subtitle),
    col = heat.colors(length(data$avgs)),
    init.angle = 45,
    radius = 0.7
)
dev.off()

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current21:51, 17 September 2013Thumbnail for version as of 21:51, 17 September 2013690 × 462 (35 KB)Pcoombe (WMF) (talk | contribs)crop
09:11, 29 December 2012Thumbnail for version as of 09:11, 29 December 2012792 × 612 (39 KB)Adamw (talk | contribs)
10:18, 28 December 2012Thumbnail for version as of 10:18, 28 December 2012792 × 612 (33 KB)Adamw (talk | contribs)
10:15, 28 December 2012Thumbnail for version as of 10:15, 28 December 2012792 × 612 (33 KB)Adamw (talk | contribs)Donation distribution between Feb 1st, 2012 and Dec 28, 2012
  • You cannot overwrite this file.

The following page uses this file:

Metadata