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.")
);
)
)
);工作流程:选择表-->选择要重新编码的列-->重新编码列(需要帮助以允许对字符和数字列进行重新编码)--->刷新列表-->选择一个或多个列-->绘制热图
需要帮助 1)调试当前脚本,我只能重新编码数字数据类型的列
2)如何选择要重新编码的字符类型列?
3) 我可以通过 jmp(columns--> Recode) 将重新编码 ui 预设作为 ui 的一部分打开吗?
此代码看起来像是由某个 LLM 编写的,因此有很多小错误和使用 JMP 没有的功能。您能否提供一个示例表,其中还包含正确的结果及其来源的解释。

这是示例 - 您重新编码“批号”以对其进行分组,然后使用“重新编码的列”绘制热图

示例 2:对测试人员进行分组,然后使用重新编码的列绘制热图
希望这有帮助
谢谢
我仍然不确定测试人员 3 应该如何变成 2,或者你从这两列中看到的是什么类型的热图




重新编码要使用什么规则?从您的示例来看,重新编码似乎只是取第 1 行和第 2 行并对其进行分组,然后取第 3 行和第 4 行并对其进行分组,等等。第一个分组的值为 1,第二个分组的值为 2,等等。
如果是这种情况,重新编码的列公式很简单
Ceiling(Row() / 2)
这是您要找的吗?它适用于字符和数字数据,因为它不依赖于 lot_no 或 tester 的值,而只依赖于行号
如果你想让用户自由使用 recode 平台,这可能并不像你想象的那么简单。
我认为你应该重新考虑你的脚本的规格。你必须具备什么,用户可以使用 JMP 平台做什么,他们是否可以在使用重新编码并选择这些新列后运行你的脚本,等等
一个列表就足够了——通过两个按钮,用户可以决定是否要重新编码或绘制所选列:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
For Each( {col}, {:age, :height, :weight}, col << Set Modeling Type( "Nominal" ) );
New Window( "simple GUI", << Type("Dialog"),
lb = Filter Col Selector( width( 150 ) ),
Button Box( "recode",
cols = lb << get selected();
dt << select columns( cols );
dt << Recode;
),
Button Box( "plot",
cols = lb << get selected();
If( N Items( cols) >= 2 ,
xcol = cols[1];
ycol = cols[2];
Graph Builder( Variables( X(Eval(xcol) ), Y( Eval(ycol) ) ), Elements( Heatmap( X, Y ) ) );
,
Caption( "select 2 columns" )
);
)
);好的,谢谢。。有没有办法我可以重新编码一列,然后使用该列绘制图形?或者打开一个新的 GUI 来绘制它?
您能否解释一下为什么要设置一个结合这两个步骤的工作流程:
- 重新编码
- 阴谋
重新编码是一个非常常见的步骤 - 但在大多数情况下,它是数据管理工作流程的一部分 - 这与数据分析有点不同。为什么要将这两个步骤结合起来?
用户是否每次都必须重新编码列才能绘制它们?
用户 A 重新编码该列后,用户 B 可以使用重新编码的列,而不必再次重新编码。或者您更喜欢一些“虚拟列”(转换列),这些列将在用户 A 之后消失,以便用户 B 可以定义自己的重新编码。
您能举个例子来说明一下您想要生成的图表吗?它总是同一种类型的图表吗?热图?应该绘制哪些列?
原始列与重新编码后的列?第 3 列与重新编码后的列?重新编码 2 列并绘制它们?