图形生成器条形图标签偏移图形生成器可以在条形图上显示值标签,不幸的是,如果数据也绘制在条形图上,则标签将被完全遮挡。

幸运的是,手动重新定位标签相对容易。获得正确的对齐有点棘手,而且多次这样做相对令人沮丧。即使在图形的第二或第三次迭代之后,编辑图形脚本以获得正确的对齐也很乏味。使用一些 JSL 魔法,我们可以找到框架和条形段并自动调整标签偏移。
在下面的脚本中打开了一个示例数据表,然后运行一个图形脚本,接着运行一些格式化指令。
要使用此脚本,请替换数据表引用或取消注释“dt=current data table();”行,让脚本再次运行当前表。图形生成器脚本是一个示例,您可以使用 RTM>保存脚本>到剪贴板来获取图形生成器脚本,然后将其粘贴到示例的位置。
names default to here(1);
//paste your data table reference here, or just use the current data table.
dt=Open( "$SAMPLE_DATA/Big Class.jmp" );
//dt=current data table();
obj=dt<<
//Paste your graph builder script here
Graph Builder(
Size( 518, 470 ),
Show Control Panel( 0 ),
Variables( X( :age ), Y( :height ) ),
Elements(
Bar(X,Y,Legend( 4 ),
Error Interval( "Standard Error" ),
Label( "Label by Value" )),
Points( X, Y, Legend( 5 ) )),
SendToReport(
Dispatch( {}, "400", ScaleBox,
{Legend Model(4,
Properties(0,{Fill Color( 0 ), Fill Pattern( "none" )},Item ID( "Mean", 1 )))}))
);
// End of graph builder script.
//Make a reference for the bar chart segments
fbi= N Items( (obj << xpath( "//FrameBox" )) );
for (ii=1, ii<=fbi, ii++,
frame = Report( obj )[FrameBox( ii )];
seg = (frame << Find Seg( "Bar Seg" ));
//Get variable used for the X axis
vars=obj<< Get Variables();
xx=vars[1];xx[1];
//Find the number of bars (or levels used to make bars)
Summarize( levels = By( eval(xx[1])));
Eval List( levels );
//Build an expression to change the offset
qq=expr(set label offset());
for (i=0, i<=nitems(levels)*fbi, i++, //Note there is a multipler, *fbi. This assumes each level is the same for each frame. Its kind of sloppy, might need to just replace it with a fixed value.
rr={};
insert into (rr, i); //This is the Bar number, starts with zero
insert into (rr,i); //This is the x offset, which is the same as the bar number
insert into(rr, 10); //This is the Y offset
insert into (qq, (rr));
);
//Make magic happen
eval(substitute(expr(seg<<QQ></QQ>
<P> </P>
<P>在之前的博客文章中,我描述了这些步骤,并包含了一个自动化脚本,用于向“Dynamite”图(带有间隔线的条形图)添加带有注释的误差线。https <A href="https://community.jmp.com/t5/Byron-Wingerd-s-Blog/One-Way-ANOVA-Figure-for-Scientists/ba-p/265156" target="_blank">://community.jmp.com/t5/Byron-Wingerd-s-Blog/One-Way-ANOVA-Figure-for-Scientists/ba-p/265156</A></P><LINGO-TEASER id="lingo-teaser-777858" slang="en-US" mode="UPDATE"><P>您的数据是否掩盖了您的数据标签?</P></LINGO-TEASER><LINGO-LABS id="lingo-labs-777858" slang="en-US" mode="UPDATE"><LINGO-LABEL>自动化和脚本</LINGO-LABEL><LINGO-LABEL>基础数据分析与建模</LINGO-LABEL><LINGO-LABEL>数据探索与可视化</LINGO-LABEL><LINGO-LABEL>分享和交流结果</LINGO-LABEL></LINGO-LABS>回复:图形生成器条形图标签已修复嗨@Byron_JMP ,很好的技巧,非常有用。
或者,可以将标签添加到第二个条形图元素:
dt=Open( "$SAMPLE_DATA/Big Class.jmp" );
Graph Builder(
Size( 563, 522 ),
Summary Statistic( "Median" ),
Graph Spacing( 4 ),
Variables( X( :age ), Y( :height ) ),
Elements(
Bar( X, Y, Legend( 4 ), Error Interval( "Standard Error" ) ),
Points( X, Y, Legend( 5 ) ),
Bar( X, Y, Legend( 6 ), Bar Style( "Float" ), Label( "Label by Value" ) )
)
);
我经常遇到一个相关的问题:没有水平标签的空间:

是否有通过 JSL 来旋转标签的解决方法?
回复:图形生成器条形图标签已修复听起来您希望标签像这样旋转:

如果没有你的问题,我也不会尝试。有一些晦涩难懂的 JSL 可以让你设置字体属性和角度。老实说,我以前从未见过这样做,而且看起来非常棒。
JSL 如下:设置字体( “” , 18 , “” , 90 )。字体为“”,大小为 18 点,格式为“”,角度为 90。在脚本索引中,示例指定了字体和格式,但将其替换为“”,似乎使用了默认值。将角度更改为 -90 会使文本从下往上阅读。
names default to here(1);
//paste your data table reference here, or just use the current data table.
dt=Open( "$SAMPLE_DATA/Big Class.jmp" );
//dt=current data table();
obj=dt<<
//Paste your graph builder script here
Graph Builder(
Size( 518, 470 ),
Show Control Panel( 0 ),
Variables( X( :age ), Y( :height ) ),
Elements(
Bar(X,Y,Legend( 4 ),
Error Interval( "Standard Error" ),
Label( "Label by Value" )),
Points( X, Y, Legend( 5 ) )),
SendToReport(
Dispatch( {}, "400", ScaleBox,
{Legend Model(4,
Properties(0,{Fill Color( 0 ), Fill Pattern( "none" )},Item ID( "Mean", 1 )))}),
Dispatch( {}, "Graph Builder", FrameBox,
{DispatchSeg(
BarSeg( 1 ),
Set Font( "", 18, "", 90 )
)}
)
)
);
// End of graph builder script.
//Make a reference for the bar chart segments
fbi= N Items( (obj << xpath( "//FrameBox" )) );
for (ii=1, ii<=fbi, ii++,
frame = Report( obj )[FrameBox( ii )];
seg = (frame << Find Seg( "Bar Seg" ));
//Get variable used for the X axis
vars=obj<< Get Variables();
xx=vars[1];xx[1];
//Find the number of bars (or levels used to make bars)
Summarize( levels = By( eval(xx[1])));
Eval List( levels );
//Build an expression to change the offset
qq=expr(set label offset());
for (i=0, i<=nitems(levels)*fbi, i++, //Note there is a multipler, *fbi. This assumes each level is the same for each frame. Its kind of sloppy, might need to just replace it with a fixed value.
rr={};
insert into (rr, i); //This is the Bar number, starts with zero
insert into (rr,i); //This is the x offset, which is the same as the bar number
insert into(rr, 10); //This is the Y offset
insert into (qq, (rr));
);
//Make magic happen
eval(substitute(expr(seg<<QQ></QQ>
<P> </P>回复:图形生成器条形图标签偏移太酷了!太神奇了!
谢谢。
回复:图形生成器条形图标签偏移嗯……
我只是想知道如何才能将标签从图表顶部移开...无需任何 JSL。
-> 啊:JMP17!
因此,作为“条形图标签偏移”的另一种解决方法:
切换回JMP 17 ,并将用户年龄放在 x 轴上并叠加:
// JMP 17!
Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << new column("one", set each value(1));
dt << Graph Builder(
Variables( X( :age ), Y( :height ), Overlay( :age ), Color( :one ) ),
Elements(
Bar(
X,
Y,
Legend( 1 ),
Summary Statistic( "Mean" ),
Error Interval( "Standard Error" ),
Label( "Label by Value" )
),
Points( X, Y, Overlay( 0 ), Legend( 2 ) )
),
SendToReport(
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
1,
Properties(
0,
{Fill Color( 0 ), Fill Pattern( "none" )},
Item ID( "1", 1 )
)
), Legend Model(
2,
Properties( 0, {Line Color( 0 )}, Item ID( "1", 1 ) )
)}
)
)
);

缺点:
- 错误栏似乎有一个错误,已使用 JMP18 修复。
- 没有 JMP 18 的其他酷炫功能。
回复:图形生成器条形图标签偏移考虑所有没有 JSL 经验的 JMP 用户......
实际上,应该在 GUI 中有一个用于控制标签放置的控件。
啊, @shampton82在 2020 年提出了一个愿望,这个想法:
图形生成器条形图数据标签控件
回复:图形生成器条形图标签偏移感谢@hogi链接此博客和愿望清单项目!虽然我们能够使用 JSL 添加如此多的功能,这很棒,但在展示 JMP 时最尴尬的事情之一是无法使用图表自定义功能执行用户可以在 excel 中执行的非常基本的事情(并且他们已经习惯了,他们惊讶于您无法在 JMP 中轻松做到这一点)。
@Byron_JMP请与 JMP 团队合作,使这一伟大的定制变得非基于 JSL!
史蒂夫
回复:图形生成器条形图标签偏移同意。
回复:图形生成器条形图标签偏移我刚刚发现 JMP 17 和 JMP18 之间有什么区别:
切换到堆叠模式时,标签将位于 JMP18 的中心。
不幸的是,这种模式与错误栏不兼容。
因此,必须使用另一个浮动条形图添加误差线。
总共:

100% GUI – 0% 脚本。
脚本如下:
查看更多...Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Graph Builder(
Size( 521, 429 ),
Variables( X( :age ), Y( :height ) ),
Elements(
Points( X, Y, Legend( 2 ) ),
Bar(
X,
Y,
Bar Style( "Stacked" ),
Summary Statistic( "Mean" ),
Label( "Label by Value" )
),
Bar(
X,
Y,
Bar Style( "Float" ),
Summary Statistic( "Mean" ),
Error Interval( "Standard Error" )
)
)
);
... 我希望这篇文章不会被用来反对指定标签位置的新功能。
回复:图形生成器条形图标签偏移感谢这些帖子。这将会很有帮助。
回复:图形生成器条形图标签偏移热图是否也有一个“seg”可以对话?
不在此列表中:

它被称为Heatmap Cells Seg吗?
myseg << get description = "Heatmap Cells";
-> 没有。
回复:图形生成器条形图标签偏移矩形段。
不幸的是,Heatmap Seg = Rect Seg 相当不灵敏:(