|
| 1 | +classdef PairPlot < imagem.actions.CurrentTableAction |
| 2 | +% Pair-wise scatter plot of table columns. |
| 3 | +% |
| 4 | +% Class PairPlot |
| 5 | +% |
| 6 | +% Example |
| 7 | +% PairPlot |
| 8 | +% |
| 9 | +% See also |
| 10 | +% |
| 11 | + |
| 12 | +% ------ |
| 13 | +% Author: David Legland |
| 14 | + |
| 15 | +% Created: 2020-12-23, using Matlab 9.8.0.1323502 (R2020a) |
| 16 | +% Copyright 2020 INRAE - BIA-BIBS. |
| 17 | + |
| 18 | + |
| 19 | +%% Properties |
| 20 | +properties |
| 21 | +end % end properties |
| 22 | + |
| 23 | + |
| 24 | +%% Constructor |
| 25 | +methods |
| 26 | + function obj = PairPlot(varargin) |
| 27 | + % Constructor for PairPlot class. |
| 28 | + |
| 29 | + end |
| 30 | + |
| 31 | +end % end constructors |
| 32 | + |
| 33 | + |
| 34 | +%% Methods |
| 35 | +methods |
| 36 | + function run(obj, frame) %#ok<INUSL> |
| 37 | + |
| 38 | + table = frame.Doc.Table; |
| 39 | + |
| 40 | + % identify numeric columns |
| 41 | + inds = ~isFactor(table, 1:size(table, 2)); |
| 42 | + colNames = table.ColNames(inds); |
| 43 | + |
| 44 | + % Open a dialog for choosing the columns to display |
| 45 | + [numColInds, ok] = listdlg(... |
| 46 | + 'ListString', colNames, ... |
| 47 | + 'Name', 'Pair Plot', ... |
| 48 | + 'PromptString', 'Columns To Plot:', ... |
| 49 | + 'ListSize', frame.Gui.Options.DlgListSize, ... |
| 50 | + 'SelectionMode', 'Multiple'); |
| 51 | + |
| 52 | + if ~ok || isempty(numColInds) |
| 53 | + return; |
| 54 | + end |
| 55 | + |
| 56 | + % If Table has factor columsn, add possibility to choose one |
| 57 | + factorIndex = -1; |
| 58 | + factorColumnName = ''; |
| 59 | + inds = isFactor(table, 1:size(table, 2)); |
| 60 | + if any(inds) |
| 61 | + factorColumnNames = table.ColNames(inds); |
| 62 | + % creates a new dialog, and populates it with some fields |
| 63 | + gd = imagem.gui.GenericDialog('Pair Plot Factor'); |
| 64 | + addCheckBox(gd, 'Color by Factor Levels', true); |
| 65 | + addChoice(gd, 'Factor Column: ', factorColumnNames, factorColumnNames{1}); |
| 66 | + |
| 67 | + % displays the dialog, and waits for user |
| 68 | + showDialog(gd); |
| 69 | + % check if ok or cancel was clicked |
| 70 | + if wasCanceled(gd) |
| 71 | + return; |
| 72 | + end |
| 73 | + |
| 74 | + % parse the user inputs |
| 75 | + if getNextBoolean(gd) |
| 76 | + factorColumnName = getNextString(gd); |
| 77 | + factorIndex = columnIndex(table, factorColumnName); |
| 78 | + end |
| 79 | + end |
| 80 | + |
| 81 | + % create pattern for writing history |
| 82 | + numColNames = table.ColNames(numColInds); |
| 83 | + nc = length(numColNames); |
| 84 | + pattern = ['{''%s''' repmat(', ''%s''', 1, nc-1) '}']; |
| 85 | + numColsString = sprintf(pattern, numColNames{:}); |
| 86 | + |
| 87 | + % create Plot Pair display |
| 88 | + createPlotFrame(frame.Gui); |
| 89 | + if factorIndex > 0 |
| 90 | + % plot using factor levels |
| 91 | + pairPlot(table(:, numColInds), table(:, factorIndex)); |
| 92 | + % create history string |
| 93 | + historyString = sprintf('figure; pairPlot(%s(%s), %s(''%s''));\n', ... |
| 94 | + frame.Doc.Tag, numColsString, frame.Doc.Tag, factorColumnName); |
| 95 | + else |
| 96 | + % plot without factor |
| 97 | + pairPlot(table(:, numColInds)); |
| 98 | + % create history string |
| 99 | + historyString = sprintf('figure; pairPlot(%s(%s));\n', ... |
| 100 | + frame.Doc.Tag, numColsString); |
| 101 | + end |
| 102 | + |
| 103 | + % add to history |
| 104 | + addToHistory(frame, historyString); |
| 105 | + |
| 106 | + end |
| 107 | +end % end methods |
| 108 | + |
| 109 | +end % end classdef |
| 110 | + |
0 commit comments