cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
ron_horne
Super User (Alumni)

wrap axis lables

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
ms
Super User (Alumni) ms
Super User (Alumni)

Re: wrap axis lables

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

View solution in original post

5 REPLIES 5
ms
Super User (Alumni) ms
Super User (Alumni)

Re: wrap axis lables

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 (Alumni)

Re: wrap axis lables

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 (Alumni) ms
Super User (Alumni)

Re: wrap axis lables

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 (Alumni)

Re: wrap axis lables

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
Level I

Re: wrap axis lables

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!