大家好,
我正在尝试为表格摘要的每个元素绘制带有参考线的图表(脚本,JMP 13)(每个名称+成绩的分数与尝试次数的图表,然后在x轴上添加分数的25和75百分位的参考线) 。 如有任何评论,将不胜感激
| 姓名 | 年级 | 分数 | # 尝试 |
| 姓名1 | A | 80 | 2 |
| 姓名1 | A | 82 | 3 |
| 姓名1 | 乙 | 98 | 3 |
| 姓名1 | C | 86 | 2 |
| 姓名2 | A | 88 | 3 |
| 姓名3 | A | 90 | 2 |
| 姓名3 | A | 88 | 1 |
| 姓名3 | A | 94 | 3 |
| 姓名4 | 乙 | 96 | 2 |
| 姓名4 | 乙 | 82 | 4 |
| 姓名4 | A | 100 | 1 |
| 姓名4 | C | 92 | 2 |
| 姓名5 | A | 84 | 3 |
你好@旋转起来,
我想我明白你想要什么。 但是,我也有点困惑:你是想总结还是只是绘制 9 个独立的双变量图?
使用原始数据表,如果进行二元拟合,则可以轻松创建所有 9 个图表,例如:
Bivariate(
Y( :Score ), X( :Name( "# try" ) ),
By( :Name, :Grade )
);
这将生成您在上一篇文章中着色的九张图表。
然后,您可能需要做的是使用 For 循环来生成分位数线(或阴影区域)。
第一个图的脚本类似于:
Bivariate(
Y( :Score ),
X( :Name( "# try" ) ),
Where( :Name == "name1" & :Grade == "A" ), // this would be selecting
SendToReport(
Dispatch(
{},
"2",
ScaleBox,
{Min( 75 ), Max( 100 ), Inc( 5 ), Minor Ticks( 1 ), // this sets the appearance of the y-axis
Add Ref Line( 83, "Solid", "Blue", "25th quantile", 1 ),
Add Ref Line( 95, "Solid", "Blue", "75th quantile", 1 )}
)
)
);事实上,如果您设置名称列表 NameList={"Name1", "Name2"...},或者从列元素中提取它,那么您可以通过放入 For 循环来获得一个非常短的脚本,只需我们引用 NameList[i] 元素。 对于Where(:Name==NameList[i] & Grade == GradeList[i]) 也是如此。
另一种选择是检查上面包含的第一个脚本的输出的树结构,然后为 9 个图表的每个 y 轴引用 AxisBox(i)。 y 轴都是奇数,因此如果您执行 For 循环,则必须执行 i++,以便它在循环中从 1 迭代到 3 到 5,依此类推。
链接中有一些非常好的东西@Craige_Hales假如。
对于您的具体问题,我认为您肯定需要进行一些循环。 或者,您也可以手动完成整个过程一次,然后将脚本保存到数据表(可能作为一个组),然后您可以复制/粘贴该脚本并在新的脚本窗口中另存为单独的 JSL 文件。 如果您能够弄清楚如何手动执行此操作,JMP 将为您编写 JSL,而您所需要做的就是将其全部放入一个主 JSL 文件中,该文件会为您处理所有事宜。 唯一的问题是您是否决定更改名称或列引用或类似的内容。 如果这样做,那么您将需要开始使用局部变量。
希望这可以帮助!,
DS
也许是这样的
dtBigClass = Open( "$sample_data/big class.jmp" );
dtage = dtBigClass << Summary( Group( :age ) ); // makes a small table of unique ages
ages = dtage[0, 1]; // [12, 13, 14, 15, 16, 17]
Close( dtage, "nosave" ); // table no longer needed
grid = Lineup Box( N Col( 3 ), spacing( 20, 30 ) ); // Horz,Vert extra space between graphs in pixels
For( iAge = 1, iAge <= N Rows( ages ), iAge += 1, // for each age...
dtBigClass << selectwhere( age == ages[iAge] );
dtSubset = dtBigClass << subset( selectedrows( 1 ), linked( 1 ), "invisible" );
// the summary will be a single row with the requested information
dtSummary = dtSubset << Summary( Mean( :height ), Mean( :weight ), Std Dev( :height ), Std Dev( :weight ), Freq( "None" ), Weight( "None" ) );
// grab the values of interest in simpler variable names
heightMean = dtSummary:name( "Mean(height)" )[1]; // row one has the answers
heightStdDev = dtSummary:name( "Std Dev(height)" )[1];
weightMean = dtSummary:name( "Mean(weight)" )[1];
weightStdDev = dtSummary:name( "Std Dev(weight)" )[1];
Close( dtSummary, "nosave" ); // close the work table, no longer needed
// make a graph, attach to a borderbox so it does not open in a window...
bb = Border Box(
dtSubset << Graph Builder(
Size( 400, 300 ),
Show Control Panel( 0 ),
Show Legend( 0 ), // don't need a legend
Variables( X( :height ), Y( :weight ) ),
Elements( Points( X, Y, Legend( 5 ) ) ),
// add ref lines. You can get a script like this GraphBuilder script by
// making a graph builder interactively, then using the red triangle->get script.
// below, the numbers in the script have been replaced with the variables above.
SendToReport(
Dispatch(
{},
"height",
ScaleBox,
{Add Ref Line( heightMean, "Dotted", "Red", "", 2 ), Add Ref Line( heightMean + heightStdDev, "Dotted", "Blue", "", 2 ),
Add Ref Line( heightMean - heightStdDev, "Dotted", "Blue", "", 2 ),
// force all axes to be the same...
Min( 48.2828947368421 ), Max( 75.8776488919668 ), Inc( 5 ), Minor Ticks( 1 )}
),
Dispatch(
{},
"weight",
ScaleBox,
{Add Ref Line( weightMean, "Dotted", "Red", "", 2 ), Add Ref Line( weightMean + weightStdDev, "Dotted", "Blue", "", 2 ),
Add Ref Line( weightMean - weightStdDev, "Dotted", "Blue", "", 2 ),
// force all axes to be the same...
Min( 55.2100840336134 ), Max( 188.127074359155 ), Inc( 20 ), Minor Ticks( 0 )}
),
Dispatch( {}, "Graph Builder", FrameBox, {Marker Size( 6 ), Transparency( 1 )} ), // make the markers bigger
Dispatch( {}, "graph title", TextEditBox, {Set Text( "Age = " || Char( ages[iAge] ) )} ), // add the age= title
Dispatch( {}, "Graph Builder", OutlineBox, {Set Title( "" )} ) // suppress the Graph Builder title
)
)
);
grid << append( bb ); // add the graph to the grid
); // the iAge loop
dtBigClass << clearRowStates; // undo the final selection
New Window( "the report", V List Box( H Center Box( Text Box( "Big Report", <<SETFONTSIZE></SETFONTSIZE>
Reports grouped in a 3-wide gridReports grouped in a 3-wide grid报告分组在 3 宽网格中
谢谢@SDF1对于您的回复,很抱歉不太清楚。 在这里我想再解释一下:
首先,我尝试在单独的脚本窗口中编写脚本,以便我可以独立运行它,这是脚本的第一部分,我试图在其中获取摘要:
Names Default To Here( 1 );
dt = Current Data Table();
Summary = dt << Summary(
Group( :Name, :Grade ),
Median( :Score ),
// other statistics can be added here//
Link to Original Data Table( 0 )
);
输出将如下所示:

现在,我真正想要的是 9 个图表( Score vs # try)(每行一个(有 N 行数据点)),然后使用每组的统计数据添加到参考线(全部通过脚本编写)。
在您的图表示例中,看起来它适用于任何等级的 name1。
谢谢
你好@旋转起来,
我不确定我完全理解你想要做什么,但你可能很难完全编写整个事情的脚本。 如果您将数据表保留一段时间或将其加载,您可能需要单独进行分析,然后将它们保存到数据表中。
如果您确实想编写整个过程的脚本,您仍然需要运行分析来确定 25/75 分位数等。
当你说你正在绘制“分数与#尝试”的图表时,你的意思是当你执行“通过x拟合y”时,分数是“y”而“#尝试”是“x”?
另外,当您说表格摘要时,您的意思是在按名称和成绩分组时找到分数和#try 的平均值吗? 或者,您的意思是您正在按名称列出成绩并查找分数和#try 值的平均值?
不过,你可以通过几种方式做到这一点。 我把你的表格带入 JMP,这就是我所做的(假设我和你的想法一样):
按名称制表(A、B、C 是 # 项),这有助于获取方法,但如果需要,您可以单独编写脚本。

有了这个,我用几种不同的方式绘制了它:二元拟合或直方图(直方图已经可以从箱线图中轻松获得四分位信息)。然后您可以通过正常方式添加参考线。


为了编写所有这些脚本,请务必使用红色热按钮访问实际的 JSL 脚本以生成您想要的内容。 但同样,如果您将脚本保存到数据表中,那么每次打开数据表时,您都可以单击绿色热按钮并快速重新运行它。
希望这可以帮助!,
DS