Utiliser des expressions pour le format de thèmeJ'essaie de transformer le formatage de plusieurs tracés similaires en une expression afin de pouvoir modifier une seule section du code pour mettre à jour tous les tracés qui se ressemblent. Cependant, j'ai du mal à l'implémenter dans le code. J'inclus un exemple de travail minimal montrant à quoi je voudrais qu'un tracé ressemble et à quoi je voudrais que mon code ressemble, en stockant un morceau de code pour le formatage et un code compact pour chaque tracé. Avez-vous une idée sur la façon dont je peux modifier cela pour que cela fonctionne ? Je travaille sur JMP version 15.2.
dt = New Table( "Minimal Working Example",
Add Rows( 400 ),
New Column( "X", Numeric, Set Values( Repeat( 1 :: 20, 20 ) ) ),
New Column( "Y", Numeric, Set Values( Sort Ascending( Shape( Repeat( 1 :: 20, 20 ), 1 ) ) ) ),
New Column( "Size", Numeric, <<FORMULA></FORMULA>
<LINGO-LABS id="lingo-labs-398923" slang="en-US" mode="UPDATE"><LINGO-LABEL>Modélisation statistique avancée</LINGO-LABEL><LINGO-LABEL>Accès aux données</LINGO-LABEL><LINGO-LABEL>Mélange et nettoyage des données</LINGO-LABEL><LINGO-LABEL>Personnalisation de masse</LINGO-LABEL></LINGO-LABS>Re: Utiliser des expressions pour le format de thèmeSalut,
La gestion des expressions est puissante et demande un peu de pratique. Voici un exemple pour vous aider à démarrer, mais vous voudrez vous renseigner sur des choses comme Eval(), Expr(), NameExpr(), Substitute(), Substitute Into(), etc.
Names Default To Here(1);
//make a 5-column table
dt = astable((1::20)` || J(20,4,randominteger(0,20)));
//the x column will be the first column
xCol = column (dt, 1);
//the y columns will be the remaining columns
yColList = (dt << get column names())[2::ncol(dt)];
//write the graph builder script, wrapping it in an expression. Use _XXX_ format for things
//you'll be substituting later. Here, that is just the "y" variable for a particular graph.
gbExpr = expr(
dt << Graph Builder(
Variables( X( xcol ), Y( _Y_ ) ),
Elements( Points( X, Y, Legend( 8 ) ) ),
SendToReport(
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
8,
Properties(
0,
{gradient( {Color Theme( "White to Red" )} )},
Item ID( "Size", 1 )
)
)}
),
Dispatch(
{},
"400",
LegendBox,
{Legend Position( {8, [0, -1]} ), Legend Position( {0, -1} )}
)
)
);
);
//cycling through the items in yColList, we create a graph for each y variable vs the x variable.
//be sure to read up on Name Expr ( ), as it is needed here to prevent evaluation of the Graph
//Builder script... we just want the code itself... we don't want JMP to try to evaluate the code
//until after we've made the substitution.
for (i = 1,i <=nitems(ycolList), i++,
eval(Substitute( nameExpr(gbExpr), expr(_Y_) , expr(yColList[i])));
);
Acclamations,
Brady
Re : Utiliser des expressions pour le format de thèmeCela n'a pas très bien fonctionné en raison de la façon dont les variables X, Y et Color changent sur mes données, mais j'ai réussi à trouver une solution plus proche de ce que je voulais en utilisant JSL Quote, Eval Insert, Parse et Eval :
// A theme format I could change for a gazillion of plots
formats = JSL Quote(
SendToReport(
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
8,
Properties(
0,
{gradient( {Color Theme( "White to Red" )} )},
Item ID( "Size", 1 )
)
)}
),
Dispatch(
{},
"400",
LegendBox,
{Legend Position( {8, [0, -1]} ), Position( {0, -1} )}
)
)
);
// How I would like each plot code to look like
Eval(Parse(Eval Insert("dt << Graph Builder(
Variables( X( :X ), Y( :Y ), Color( :Size ) ),
Elements( Points( X, Y, Legend( 8 ) ) ),
^formats^
);")));