Dimension Reduction - Plot - Component Plot Extension

From Q
Jump to navigation Jump to search
This page is currently under construction, or it refers to features which are under development and not yet available for use.
This page is under construction. Its contents are only visible to developers!


Chart the first two components or factors from a principal components analysis or factor analysis (created, for example, with Insert > More > Dimension Reduction > Principal Components Analysis).

Example

Example output:


Example input:


Options

Principal components analysis An R Output containing a factor analysis or principal components analysis. This does not need to be created with Insert > More > Dimension Reduction > Principal Components Analysis (you can make your own factor analysis or PCA), but the item does need to have a property called loadings.

Show variable labels on plot Whether or not the labels found in the loadings will be displayed in the chart.

Code

var __webpack_modules__ = ({});
// The module cache
var __webpack_module_cache__ = {};

// The require function
function __webpack_require__(moduleId) {

// Check if module is in cache
var cachedModule = __webpack_module_cache__[moduleId];
if (cachedModule !== undefined) {
return cachedModule.exports;
}
// Create a new module (and put it into the cache)
var module = (__webpack_module_cache__[moduleId] = {
exports: {}
});
// Execute the module function
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);

// Return the exports of the module
return module.exports;

}

// webpack/runtime/rspack_version
(() => {
__webpack_require__.rv = () => ("1.7.2")
})();
// webpack/runtime/rspack_unique_id
(() => {
__webpack_require__.ruid = "bundler=rspack@1.7.2";
})();
includeWeb("QScript R Output Functions");

const is_displayr = (!!Q.isOnTheWeb && Q.isOnTheWeb());
// Separate selected item from the group/page
const selected_items = project.report.selectedRaw();
const selected_item = selected_items[0];
const selected_group = selected_item.group; // selected item is an R item, therefore it must have a group
// Add custom R code
const output_name = generateUniqueRObjectName("component.plot");
const r_expr = "library(flipDimensionReduction)\n" +
    output_name + " <- ComponentPlot(inputItem, show.labels = formShowLabels)";
let component_plot;
if (is_displayr && selected_group.group !== null && project.currentPage() !== null) { // if current page is null, the item is a single output node
    const plot_group = selected_group.group.appendPage("Item");
    plot_group.subItems[0].text = "Component Plot";
    plot_group.name = "Component Plot";
    component_plot = plot_group.appendR(r_expr);
    selected_group.group.moveAfter(plot_group, selected_group);
    project.report.setSelectedRaw([plot_group]);
}
else {
    component_plot = is_displayr ? selected_group.appendR(r_expr, true) : selected_group.appendR(r_expr);
    selected_group.moveAfter(component_plot, selected_item);
    project.report.setSelectedRaw([component_plot]);
}
// Check if TextPCA output is used to update the variable label control as required
const not_text_pca = selected_item.outputClasses.indexOf("TextPCA") < 0 ? 'true' : 'false';
// Create GUI controls
const javascript_inputs_expr = 'form.setHeading("Component Plot");\n' +
    'form.dropBox({name: "inputItem", label: "Principal components analysis", types: ["R"],\n' +
    '              prompt: "Output of PCA"});\n' +
    'form.checkBox({name: "formShowLabels", label: "Show variable labels on plot", default_value: ' + not_text_pca + '});';
component_plot.setCodeForGuiControls(javascript_inputs_expr);
// Use the selected flipFactorAnalysis output as the input to the plot.
component_plot.setGuiControlInputRaw("inputItem", selected_item.guid);