大家好,
我有一个看似简单的问题,但我找不到答案。 我制作了一个条形图,想单独定制每个条形图的填充颜色。 该图是 y 轴上的成本和 x 轴上的汽车制造,每辆汽车制造有两年。 原因是我有一个一般的填充颜色,具体取决于年份(2017 年和 2018 年),但想突出显示某些汽车制造不同的颜色(例如,本田 2017 将与其他 2017 年汽车制造不同,而本田 2018 将是与 2018 年其他汽车品牌不同)。
有没有办法在图形构建或完整代码上轻松做到这一点?
提前致谢。
下面的脚本扩展了 Jim 的, @txnelson , 很好的建议,演示了如何使用 JSL 修改设置特定的颜色图例模型。
Names Default to Here(1);
dt = open("$sample_data/big class.jmp");
gb = dt << Graph Builder(
show control panel(0),
Variables(
X( :age ),
X( :sex, Position( 1 ) ),
Y( :height ),
Color(
Transform Column(
"Transform[age]",
Character,
Nominal,
Formula( (Char( :age ) || " ") || :sex )
)
)
),
Elements( Bar( X( 1 ), X( 2 ), Y, Legend( 12 ) ) )
);
//note Item ID count begins with 0
gb << SendToReport(
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
//12,
Properties( 0, {Fill Color( 5 )}, Item ID( "12 F", 1 ) ),
Properties( 1, {Fill Color( 5 )}, Item ID( "12 M", 1 ) ),
Properties( 2, {Fill Color( 20 )}, Item ID( "13 F", 1 ) ),
Properties( 3, {Fill Color( 20 )}, Item ID( "13 M", 1 ) ),
Properties( 4, {Fill Color( 6 )}, Item ID( "14 F", 1 ) ),
Properties( 5, {Fill Color( 6 )}, Item ID( "14 M", 1 ) ),
Properties( 6, {Fill Color( 27 )}, Item ID( "15 F", 1 ) ),
Properties( 7, {Fill Color( 27 )}, Item ID( "15 M", 1 ) ),
Properties( 8, {Fill Color( 26 )}, Item ID( "16 F", 1 ) ),
Properties( 9, {Fill Color( 26 )}, Item ID( "16 M", 1 ) ),
Properties( 10, {Fill Color( 12 )}, Item ID( "17 F", 1 ) ),
Properties( 11, {Fill Color( 12 )}, Item ID( "17 M", 1 ) )
)}
)
);

一种解决方案是创建一个新列,它是 Year 和 Car 列的串联
结合= char(:年)|| “”|| :车;
然后使用这个新列作为图形生成器中的颜色列。 然后,您可以将每个单独的条形图设置为您想要的任何颜色。下面是使用 Big Class 示例数据表的类似示例

有时我也有同样的问题。
由于 A 列有 6 个元素,B 列有 2 个元素,手动为 6x2 不同子集着色仍然很有趣。
但在其他情况下,手动分配正确的颜色需要花费一些时间。
应用案例:
- 使用 A 列作为颜色
- 使用 B 列 = excepted() 为排除点指定灰色
对于此类应用, GraphBuilder:覆盖 Dropzone可能是一个强大的功能。