Names Default To Here(1);
// Function to recode a selected column
recode_column = Function({dataTable, columnToRecode, newColumnName},
// Check if column exists
If(Column(dataTable, columnToRecode) != {},
// Create a mapping for recoding
aa_recode = Associative Array();
For(i = 1, i <= N Row(dataTable), i++,
aa_recode[Column(dataTable, columnToRecode) << Get Value(i)] = Column(dataTable, columnToRecode) << Get Value(i);
);
dataTable << New Column(newColumnName, Character, Nominal, << Set Each Value(
aa_recode[Column(dataTable, columnToRecode)]
));
cols = {};
For(i = 1, i <= N Col(dataTable), i++,
cols[N Items(cols) + 1] = Column(dataTable, i) << Get Name
);
recodeColListBox << Set Items(cols);
colorColListBox << Set Items(cols); // Refresh heatmap plotting list
Show Message("Column recoded and new column added: " || newColumnName);
,
Show Message("Selected column does not exist.")
);
);
// Function to plot the heatmap
PlotHeatmap = Function({dataTable, colorColumnName},
If(colorColumnName != "",
Graph Builder(
Size(1500, 800),
Show Control Panel(0),
Data Table(dataTable),
Variables(
X(:x_Location),
Y(:y_Location),
Color(Column(dataTable, colorColumnName))
),
Elements(Heatmap(X, Y, Legend(4)))
)
,
Show Message("Please select a column for color.")
)
);
list = {};
For(i = 1, i <= N Table(), i++,
list[i] = Data Table(i) << Get Name
);
// Create the window
win = New Window("JMP ADDIN",
H List Box(
V List Box(
Panel Box("Choose a source data table",
dtListBox = List Box(list, max selected(1))
)
),
Button Box("Get Columns",
chosen = Data Table((dtListBox << Get Selected)[1]);
If(chosen != {},
cols = {};
For(i = 1, i <= N Col(chosen), i++,
cols[N Items(cols) + 1] = Column(chosen, i) << Get Name
);
recodeColListBox << Set Items(cols);
colorColListBox << Set Items(cols); // Refresh for heatmap plotting
,
Show Message("Please select a valid data table.")
);
),
// Panel for selecting columns to recode
V List Box(
Panel Box("Select Columns for Recode",
recodeColListBox = List Box("")
)
),
// Button to recode a column
Button Box("Recode Column",
chosen = Data Table((dtListBox << Get Selected)[1]);
recode_col = recodeColListBox << Get Selected;
If(recode_col != "",
new_col_name = "Recode_" || recode_col; // Define new column name
recode_column(chosen, recode_col, new_col_name);
// Refresh column list after recoding
cols = {};
For(i = 1, i <= N Col(chosen), i++,
cols[N Items(cols) + 1] = Column(chosen, i) << Get Name
);
recodeColListBox << Set Items(cols);
colorColListBox << Set Items(cols); // Ensure the new column is available for heatmap plotting
,
Show Message("Please select a column to recode.")
);
),
// Panel for selecting columns to plot heatmap
V List Box(
Panel Box("Select Columns for Heatmap",
colorColListBox = List Box("")
)
),
// Button to plot the heatmap
Button Box("Plot Heatmap",
selectedColorColumn = colorColListBox << Get Selected;
If(selectedColorColumn != "",
chosen = Data Table((dtListBox << Get Selected)[1]);
If(chosen != {},
PlotHeatmap(chosen, selectedColorColumn);
,
Show Message("Selected data table is invalid.")
);
,
Show Message("Please select a column for color.")
);
)
)
);
WorkFlow: Select Table--> Select Column to Recode--> Recode column(need help to allow recoding for both character and numerical column)--->Refresh column list--> select one or many columns --> Plot Heat Map
Need Help 1) debug the currect script where i can recode only numeric data type columns
2) How to include selection of Character type columns to recode?
3) Can I otherwise open the recode ui preset by jmp(columns--> Recode) as part of the ui?