如何为柱状图添加/自定义边框(轮廓)JMP社区的各位朋友,大家好!
我想在柱状图的每个柱状图周围添加边框,并自定义边框宽度。请问如何在 JMP 中实现?
如下图所示,我想在每个条形周围添加边框或轮廓。

我听说过一种变通方法,即通过叠加两个柱状图来模拟轮廓。但是,这种方法似乎无法自定义轮廓的宽度。
是否可以通过图表构建器界面或编辑脚本,为每个柱形图添加轮廓,并独立更改其颜色和宽度?
我目前使用的是 JMP 学生版 19。
提前感谢您的帮助!
基础数据分析与建模数据探索与可视化回复:如何为柱状图添加/自定义边框(轮廓)我认为使用第二个柱状图应该是一个可行的解决方案,但这需要一些工作,因为您需要创建额外的列来确保高度正确,然后再调整宽度比例。这种方法已经成功实现。

这里有一个示例脚本,您可以运行它,然后探索图表是如何构建的(条形图的顺序已更改,宽度比例已修改,颜色已更改等等……)
查看更多...
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt << New Column("Mean[height][age]",
Numeric,
"Continuous",
Formula(Col Mean(:height, :age) + 1)
);
gb = dt << Graph Builder(
Size(656, 549),
Show Control Panel(0),
Variables(
X(:age),
Y(:height),
Y(:"Mean[height][age]"n, Position(1)),
Overlay(:age)
),
Elements(
Bar(X, Y(1), Legend(6), Bar Style("Stacked")),
Bar(X, Y(2), Legend(7), Bar Style("Stacked"))
),
SendToReport(
Dispatch({}, "400", ScaleBox,
{Legend Model(
7,
Base(0, 0, 0, Item ID("12", 1)),
Base(1, 0, 1, Item ID("13", 1)),
Base(2, 0, 2, Item ID("14", 1)),
Base(3, 0, 3, Item ID("15", 1)),
Base(4, 0, 4, Item ID("16", 1)),
Base(5, 0, 5, Item ID("17", 1)),
Type Properties(0, "Bar", {Fill Color(0)}),
Properties(0, {Fill Color(0)}, Item ID("12", 1)),
Properties(1, {Fill Color(0)}, Item ID("13", 1)),
Properties(2, {Fill Color(0)}, Item ID("14", 1)),
Properties(3, {Fill Color(0)}, Item ID("15", 1)),
Properties(4, {Fill Color(0)}, Item ID("16", 1)),
Properties(5, {Fill Color(0)}, Item ID("17", 1))
)}
),
Dispatch({}, "Graph Builder", FrameBox,
{Reorder Segs({1, 2, 4}), DispatchSeg(
BarSeg(1),
{Set Width Proportion(0.7)}
)}
),
Dispatch({}, "400", LegendBox,
{Legend Position({6, [0, 1, 2, 3, 4, 5], 7, [-1, -1, -1, -1, -1, -1]})}
)
)
);
回复:如何为柱状图添加/自定义边框(轮廓)@jthi 的方案很好。我倾向于使用 JMP 的图形基元,它可以直接绘制线条和矩形,并且可以设置颜色和粗细。
有关如何执行此操作的文档和示例,请参阅脚本索引和脚本指南中的“添加图形脚本”。
回复:如何为柱状图添加/自定义边框(轮廓)其他(不错的)选择包括:
- 使用图形脚本时,您需要知道图表中有多少个柱状图,但我认为您无法从 BarSeg 对象中获取此信息。因此,在图表中添加辅助标记会更容易一些(该标记可以从最终图表中隐藏)。
- 使用标记绘制表达式。虽然需要添加标记,实现起来也更复杂,但它很可能是一种更稳健的选择。
我现在没时间把这些选项都写下来,但它们确实存在。
回复:如何为柱状图添加/自定义边框(轮廓)有时间创建图形脚本
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
Size(656, 549),
Show Control Panel(0),
Variables(X(:age), Y(:height)),
Elements(
Bar(X, Y, Legend(4)),
Points(X, Y, Legend(5), Summary Statistic("Mean"))
),
SendToReport(
Dispatch({}, "400", ScaleBox,
{Legend Model(
5,
Type Properties(0, "Marker", {Transparency(0)}),
Properties(0, {Transparency(0)}, Item ID("Mean", 1))
)}
)
)
);
fb = Report(gb)[FrameBox(1)];
fb << Add Graphics Script(Function({this}, // can be laggy as it is a graphic script with a loop
ms = this << Find Seg(MarkerSeg(1));
xs = ms << Get X Values;
ys = ms << Get Y Values;
sideshift = 0.27;
For(i = 1, i <= N Items(xs), i++,
Pen Size(10); // Width of the line
Pen Color("Black");
Rect(xs[i] - sideshift, ys[i], xs[i] + sideshift, -1, 0);
);
));

这里是 Marker Draw Expr
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
Size(656, 549),
Show Control Panel(0),
Variables(X(:age), Y(:height)),
Elements(
Bar(X, Y, Legend(4)),
Points(X, Y, Legend(5), Summary Statistic("Mean"))
),
SendToReport(
Dispatch({}, "400", ScaleBox,
{Legend Model(
5,
Type Properties(0, "Marker", {Transparency(0)}),
Properties(0, Item ID("Mean", 1))
)}
)
)
);
fb = Report(gb)[FrameBox(1)];
seg = (fb << FindSeg(Marker Seg(1)));
seg << Set Marker Draw Expr(
Function({this seg, this row, x, y, size, row state},
Pen Size(10); // Width of the line
Pen Color("Black");
Rect(x - 0.27, y, x + 0.27, -1, 0);
)
);

回复:如何为柱状图添加/自定义边框(轮廓)@jthi ,
在我的 JMP 19 安装中,“标记绘制表达式”示例无法正常工作。标记的透明度默认值似乎被设置为 0。下面的简单更改可以让矩形正确显示。
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
Size(656, 549),
Show Control Panel(0),
Variables(X(:age), Y(:height)),
Elements(
Bar(X, Y, Legend(4)),
Points(X, Y, Legend(5), Summary Statistic("Mean"))
),
SendToReport(
Dispatch({}, "400", ScaleBox,
{Legend Model(
5,
Type Properties(0, "Marker", {Transparency(0)}),
Properties(0, Item ID("Mean", 1))
)}
)
)
);
fb = Report(gb)[FrameBox(1)];
seg = (fb << FindSeg(Marker Seg(1)));
seg << Set Marker Draw Expr(
Function({this seg, this row, x, y, size, row state},
show(x,y);
Pen Size(10); // Width of the line
Pen Color("Black");
transparency(1); // Needed for JMP 19
Rect(x - 0.27, y, x + 0.27, -1, 0);
)
);
回复:如何为柱状图添加/自定义边框(轮廓)如果您觉得细线作为边框可以接受,那就非常简单:只需添加第二个条形图,并将pattern 设置为“none” ,然后将颜色调整为例如黑色。

Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Graph Builder(
Size( 469, 365 ),
Summary Statistic( "Median" ),
Variables( X( :age ), Y( :height ), Overlay( :sex ), Color( :sex ) ),
Elements(
Bar( X, Y, Bar Style( "Stacked" ) ),
Bar( X, Y, Legend( 2 ), Bar Style( "Stacked" ) )
),
SendToReport(
Dispatch( {}, "400", ScaleBox,
{Legend Model(
2,
Properties(
0,
{Fill Color( 0 ), Fill Pattern( "none" )},
Item ID( "F", 1 )
),
Properties(
1,
{Fill Color( 0 ), Fill Pattern( "none" )},
Item ID( "M", 1 )
)
)}
)
)
);
回复:如何为柱状图添加/自定义边框(轮廓)@txnelson
非常感谢您的详细回复,这对我很有帮助。但我还有一件事想请教。
当我使用“设置标记绘制表达式”绘制条形边框时,它会绘制在顶层。
因此,当我添加误差线或单个数据点(通过点图)时,自定义边框会绘制在它们上面。
有没有办法控制边框的绘制顺序(图层),使其显示在数据点的后面?
对于高度定制化的图形绘制,人们通常会使用 R 等脚本语言,还是 GraphPad Prism 等专用软件?
回复:如何为柱状图添加/自定义边框(轮廓)您可以调整各个元素的顺序:
在图表中点击右键并更改顺序:

如果只有一种地块类型,那就添加 20 个地块并进行自定义。
图形构建器的灵活性和强大程度远超人们乍看之下的想象。诀窍在于:
从非常简单的拖放操作到高度自定义的图表,实现了平滑过渡。
使用Set Marker Draw Expr,您已经体验到了一个非常复杂的功能——但它还有更多功能。
无需使用其他绘图工具。
回复:如何为柱状图添加/自定义边框(轮廓)使用新的边框和误差线绘制图表。然后右键单击图表并选择“自定义”。这将弹出一个对话框,您可以在其中选择误差线并将其移动到最前面。关闭对话框,然后点击红色三角形并选择“保存脚本”。之后,您可以查看生成的脚本,了解如何使用 JSL 将误差线移动到最前面。