你好,
我正在尝试以特定方式为曲线着色,但我找不到办法......
基本上,我有几条按标签分组的曲线。 如何为每个组显示不同颜色的所有曲线?
到目前为止,我尝试在 Graph Builder 中将“标签”放在“覆盖”部分中......但是就像那样 JMP 将一个组的所有曲线视为一条曲线。
我使用 JSL 尝试了更高级的东西(找到下面的代码)。 我能够生成曲线并访问不同的线条并独立为它们着色,但我失去了线条和标签之间的联系。
在下面的示例中:如何获得红色的本田曲线、蓝色的福特曲线和紫色的通用汽车曲线? (这当然假设我事先不知道每组中有多少条曲线,也不知道有多少组)。
有任何想法吗 ?
// Generate a simple table as example
dt = New Table( "Untitled 9050",
Add Rows( 33 ),
New Column( "Time [years]",
Numeric,
Continuous,
Format( "Best", 2 ),
Set Values(
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
)
),
New Column( "car1",
Numeric,
Continuous,
Format( "Best", 12 ),
Set Values(
[0, 0.8, 1.6, 2.4, 3.2, 4, 4.8, 5.6, 6.4, 7.2, 8, 0, 1.2, 2.4, 3.6, 4.8,
6, 7.2, 8.4, 9.6, 10.8, 12, 0, 2.2, 4.4, 6.6, 8.8, 11, 13.2, 15.4, 17.6,
19.8, 22]
)
),
New Column( "car2",
Numeric,
Continuous,
Format( "Best", 12 ),
Set Selected,
Set Values(
[0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 0, 1.4, 2.8, 4.2, 5.6, 7,
8.4, 9.8, 11.2, 12.6, 14, 0, 2.4, 4.8, 7.2, 9.6, 12, 14.4, 16.8, 19.2,
21.6, 24]
)
),
New Column( "car3",
Numeric,
Continuous,
Format( "Best", 12 ),
Set Values(
[0, 0.6, 1.2, 1.8, 2.4, 3, 3.6, 4.2, 4.8, 5.4, 6, 0, 1.6, 3.2, 4.8, 6.4,
8, 9.6, 11.2, 12.8, 14.4, 16, 0, 2.6, 5.2, 7.8, 10.4, 13, 15.6, 18.2,
20.8, 23.4, 26]
)
),
New Column( "car4",
Numeric,
Continuous,
Format( "Best", 12 ),
Set Values(
[0, 0.4, 0.8, 1.2, 1.6, 2, 2.4, 2.8, 3.2, 3.6, 4, 0, 1.8, 3.6, 5.4, 7.2,
9, 10.8, 12.6, 14.4, 16.2, 18, 0, 2.8, 5.6, 8.4, 11.2, 14, 16.8, 19.6,
22.4, 25.2, 28]
)
),
New Column( "Manufacturer",
Character( 16 ),
Nominal,
Set Values(
{"Honda", "Honda", "Honda", "Honda", "Honda", "Honda", "Honda", "Honda",
"Honda", "Honda", "Honda", "Ford", "Ford", "Ford", "Ford", "Ford",
"Ford", "Ford", "Ford", "Ford", "Ford", "Ford", "GM", "GM", "GM", "GM",
"GM", "GM", "GM", "GM", "GM", "GM", "GM"}
)
)
);
// stack the table
dt_Stack = dt << Stack(
columns( :car1, :car2, :car3, :car4 ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" )
);
// Create a graph
MyGraph = Graph Builder(
Variables( X( :Name( "Time [years]" ) ), Y( :Data ), Overlay( :Label ) ),
Elements(
Points( X, Y, Legend( 1 ), Jitter( 1 ) ),
Smoother( X, Y, Legend( 2 ) )
)
);
// Access the lines and their properties
GraphsRep = Report( MyGraph );
nbp = GraphsRep[FrameBox( 1 )] << segCount( "LineSeg" );
// Modify the lines colors
For( n = 1, n <= nbp, n++,
s = GraphsRep[FrameBox( 1 )] << FindSeg( LineSeg( n ) );
s << Line Color( "Black" );
);四点:
脚本
@XanGregg可能是正确的,您真正想要的是使用 JSL 而不是一个大图表创建或修改的一组图。 不过,以下是要尝试的两件事。
绘制线条
我很难想象你想要创建的图表,这听起来像是一张图表上有很多线条和一页长的图例。 使用透视数据,下面脚本中的顶部图表为每辆按制造商着色的汽车创建线条。只有 5 种线条样式可供使用,除了颜色之外,您无法识别图例中的车型。也许您可以使用此图表来识别汽车制造商,然后使用第二张图表按制造商分组或包装,然后按汽车着色? 这是此脚本中的底部图表,请注意,您可以单击一条线并在底部图表中查看它。
//Start with the long table in your first post.<BR />New Window("Two Graphs",
Graph Builder(
Size( 600, 400 ),
Show Control Panel( 0 ),
Variables(
X( :Name( "Time [years]" ) ),
Y( :Data ),
Overlay( :Name( "Man-Car" ) ),
Color( :Manufacturer )
),
Elements( Line( X, Y, Legend( 20 ) ) ),
SendToReport(
Dispatch(
{},
"Time [years]",
ScaleBox,
{Label Row( Show Major Grid( 1 ) )}
),
Dispatch( {}, "Data", ScaleBox, {Label Row( Show Major Grid( 1 ) )} )
)
),
Graph Builder(
Size( 604, 448 ),
Show Control Panel( 0 ),
Variables(
X( :Name( "Time [years]" ) ),
Y( :Data ),
Wrap( :Manufacturer ),
Overlay( :Label )
),
Elements( Line( X, Y, Legend( 20 ) ) ),
SendToReport(
Dispatch(
{},
"Time [years]",
ScaleBox,
{Label Row( Show Major Grid( 1 ) )}
),
Dispatch( {}, "Data", ScaleBox, {Label Row( Show Major Grid( 1 ) )} )
)
)
)
传奇
要使图例同时显示制造商和汽车,请创建一个将制造商名称与汽车名称连接起来的列。例如:
New Column( "Man:Car",
Character,
"Nominal",
Formula( :Manufacturer || " " || :Label ),
Set Selected,
Set Display Width( 108 )
)
绘制点代替
另一个想法:与其尝试显示那么多线条,不如将每条曲线汇总为您实际尝试可视化的任何内容?对于 [我假设] 简化线示例,您可以为每辆汽车绘制单独的点,显示斜率和截距。图表上的 2000 个点比 2000 条线更容易理解。 在某些时候我仍然放弃了这个传说)。在这里,我从长表开始,“按”上面创建的 Man-Car 列做了一个拟合模型,然后将估计表保存为组合表,按术语拆分表,然后绘制图表:
