Subscribe Bookmark RSS Feed

wrap axis lables

ron_horne

Super User

Joined:

Jun 23, 2011

hi all,

does anyone know how to wrap long labels of an axis in the graph builder? i have a very long variable name and it makes the graphs completely disproportionate as in the picture

2628_pastedImage_0.png

thanks,

ron

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

I can't find a direct way to wrap labels within the graphbuilder platform. One trick is to use linefeeds in the label names, i.e. in the table cell content.

I tried to automate that with jsl and it seem to work. But the graph still looks quite disproportionate because the width of the axis box does not change with width of the label and I haven't found a way that works to do that (manually or by script). See script and result below.

//Example table

dt =New Table( "example.jmp",

  Add Rows( 3 ),

  New Column( "Label", Character, Nominal,

  Set Values(

  {"This is a very long label that I wish could be wrapped", "Somewhat too long label",

  "A perfect label"}

  )

  ),

  New Column( "Data", Numeric, Continuous, Format( "Best", 12 ), Set Values( [5, 8, 2] ) )

);

// Example graph

gb = Graph Builder( Variables( Y( :Label ), X( :Data ) ), Elements( Bar( X, Y ) ) );

wrap = 15; // Select desired witdth

// Insert linefeeds at not too close spaces

col = Column( dt, "Label" );

nextspace = expr(ns=Munger( col[], wrap * n, " " ));

nextspace;

For Each Row(

  n = 1;

  nextspace;

  While( ns >= wrap,

  col[] = Munger( col[], wrap * n, " ", "\!n" );

  n++;

  nextspace;

  );

);

// Decrease axisbox width

Report( gb )[AxisBox( 2 )] << set width( 30 ); //Does not work!

2631_wraplabel.png

5 REPLIES
Solution

I can't find a direct way to wrap labels within the graphbuilder platform. One trick is to use linefeeds in the label names, i.e. in the table cell content.

I tried to automate that with jsl and it seem to work. But the graph still looks quite disproportionate because the width of the axis box does not change with width of the label and I haven't found a way that works to do that (manually or by script). See script and result below.

//Example table

dt =New Table( "example.jmp",

  Add Rows( 3 ),

  New Column( "Label", Character, Nominal,

  Set Values(

  {"This is a very long label that I wish could be wrapped", "Somewhat too long label",

  "A perfect label"}

  )

  ),

  New Column( "Data", Numeric, Continuous, Format( "Best", 12 ), Set Values( [5, 8, 2] ) )

);

// Example graph

gb = Graph Builder( Variables( Y( :Label ), X( :Data ) ), Elements( Bar( X, Y ) ) );

wrap = 15; // Select desired witdth

// Insert linefeeds at not too close spaces

col = Column( dt, "Label" );

nextspace = expr(ns=Munger( col[], wrap * n, " " ));

nextspace;

For Each Row(

  n = 1;

  nextspace;

  While( ns >= wrap,

  col[] = Munger( col[], wrap * n, " ", "\!n" );

  n++;

  nextspace;

  );

);

// Decrease axisbox width

Report( gb )[AxisBox( 2 )] << set width( 30 ); //Does not work!

2631_wraplabel.png

ron_horne

Super User

Joined:

Jun 23, 2011

thanks MS,

I ran the script but it didn't reproduce the plot in the picture. in the log i get the following:

Name Unresolved: n{3} in access or evaluation of 'n' , n

thanks!

ms

Super User

Joined:

Jun 23, 2011

It works in JMP 10 (Mac) but if I try in JMP 9 I get the same error as you. Something's changed.

esit: now I found the error: There is a redundant "nextspace" evaluation right before ForEach Loop() that includes a not-yet defined n. For some reason JMP 10 did not complain.

This works both in JMP 9 and 10:

(There is probably a more elegant way...)

//Example table

dt = New Table( "example.jmp",

  Add Rows( 3 ),

  New Column( "Label",

  Character,

  Nominal,

  Set Values(

  {"This is a very long label that I wish could be wrapped", "Somewhat too long label",

  "A perfect label"}

  )

  ),

  New Column( "Data", Numeric, Continuous, Format( "Best", 12 ), Set Values( [5, 8, 2] ) )

);

// Example graph

gb = Graph Builder( Variables( Y( :Label ), X( :Data ) ), Elements( Bar( X, Y ) ) );

wrap = 15; // Select desired witdth

// Insert linefeeds at not too close spaces

col = Column( dt, "Label" );

nextspace = Expr( ns = Munger( col[], wrap * n, " " ) );

For Each Row(

  n = 1;

  nextspace;

  While( ns >= wrap,

  col[] = Munger( col[], wrap * n, " ", "\!n" );

  n++;

  nextspace;

  );

);

ron_horne

Super User

Joined:

Jun 23, 2011

thanks!

i am actually using JMP 10 for windows.

now i do not get the error message but also can't get the wrapped plot.

many thanks!!!

MariaK

Community Member

Joined:

Jul 3, 2017

I can't seem to get this to work... has anyone had any luck with wrapping axis labels in graphs?  I'm using JMP 13.1.0

 

Thanks!