Preliminary Project Setup - Summary Plots

From Q
Jump to navigation Jump to search

Create a chart for every variable set in the data set (excluding hidden and text variable sets)

This QScript creates a chart for every question in the data file (excluding hidden questions and questions that are Text or Text - Multi).

Example

SummaryPlots.PNG

How to apply this QScript

  • Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
  • Click on the QScript when it appears in the QScripts and Rules section of the search results.

OR

  • Select Automate > Browse Online Library.
  • Select this QScript from the list.

Customizing the QScript

This QScript is written in JavaScript and can be customized by copying and modifying the JavaScript.

Customizing QScripts in Q4.11 and more recent versions

  • Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
  • Hover your mouse over the QScript when it appears in the QScripts and Rules section of the search results.
  • Press Edit a Copy (bottom-left corner of the preview).
  • Modify the JavaScript (see QScripts for more detail on this).
  • Either:
    • Run the QScript, by pressing the blue triangle button.
    • Save the QScript and run it at a later time, using Automate > Run QScript (Macro) from File.

Customizing QScripts in older versions

  • Copy the JavaScript shown on this page.
  • Create a new text file, giving it a file extension of .QScript. See here for more information about how to do this.
  • Modify the JavaScript (see QScripts for more detail on this).
  • Run the file using Automate > Run QScript (Macro) from File.

JavaScript

includeWeb('QScript Value Attributes Functions');
includeWeb('QScript Selection Functions');

var is_displayr = (!!Q.isOnTheWeb && Q.isOnTheWeb());
var data_file = requestOneDataFileFromProject(true, true, is_displayr);
   
// From here a user will have selected a file or only have one possible file in the document.
var summary_group = project.report.appendGroup();
summary_group.name = 'Summary Plots';

for (var i = 0; i < data_file.questions.length; i++) {
var q = data_file.questions[i];
    if (!q.isHidden) {
        var plot_type;
        var q_type = q.questionType;
        if (q_type == "Text" || q_type == "Text - Multi")
            continue;
        // Choose the appropriate plot type
        if (q_type == 'Pick One') {
            var non_missing_value_labels = nonMissingValueLabels(q);
            var num_categories = non_missing_value_labels.length;
            if (num_categories > 7)
                plot_type = "Column plot";
            else
                plot_type = "Pie plot";
        }
        else if (q_type == 'Pick Any' || q_type == 'Pick Any - Compact' || q_type == 'Number - Multi' || q_type == 'Ranking')
            plot_type = "Column plot";
        else if (q_type == 'Experiment')
            plot_type = "Bar plot";
        else if (q_type == 'Number' )
            plot_type = "Histogram";
        else if (q_type == 'Pick One - Multi')
            plot_type = "Stacked column plot";
        else if (q_type == 'Pick Any - Grid' || q_type == 'Number - Grid')
            plot_type = "Grid of bars plot";
        else 
            plot_type = 'Column plot';
        // Generate the plot  
        if (is_displayr) {
            var page = summary_group.appendPage("Item");
            var plot = page.appendPlot(plot_type);
            page.name = q.name;
            var titleText = page.subItems[0];
        	titleText.text = page.name;
        } else
            var plot = summary_group.appendPlot(plot_type);
        plot.primary = q;
    }
}

if (!is_displayr)
    log('A group of summary plots has been added to the project.');
else
    log('A group of summary plots has been added to the end of the Report Tree.');

See also