<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Contingency table and mosaic plot are not same orientation in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Contingency-table-and-mosaic-plot-are-not-same-orientation/m-p/81893#M37002</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// For a contingency table report, swap the x and y
// currently can swap the mosaic plot only

Names Default to Here(1);

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
myr = Contingency( Y( :Age ), X( :sex ) );

// Have to have a Contingency Analysis report open
// Can add test to make sure it is open in the future

myr = Current Report();

// taking apart CrossTabBox was easier using XML than JSL

mys = myr["Contingency Table"][CrossTabBox(1)] &amp;lt;&amp;lt; Get XML;

// get current X role or rows of contingency table

start = Contains(mys,"&amp;lt;CrosstabBoxRowsLabel&amp;gt;")+22;
end = Contains(mys,"&amp;lt;/CrosstabBoxRowsLabel&amp;gt;");
newY = Substr(mys,start,end-start);

// get current Y role or cols of contingency table
start = Contains(mys,"&amp;lt;CrosstabBoxColsLabel&amp;gt;")+22;
end = Contains(mys,"&amp;lt;/CrosstabBoxColsLabel&amp;gt;");
newX = Substr(mys,start,end-start);


// Recreate same contingency table but with X and Y flipped
// also temporarily use Value Order to match the Mosaic Plot

myValueLabels = Reverse(Associative Array(Column(dt,newX)) &amp;lt;&amp;lt; Get Keys);
Column(dt,newX) &amp;lt;&amp;lt; Set Property("Value Ordering",myValueLabels);

tempCont = Contingency( Y(Column(dt,newY) ), X(Column(dt,newX) ), Contingency Table );
tempContr = tempCont &amp;lt;&amp;lt; Report;
mycopy = tempContr["Contingency Table"][CrossTabBox(1)] &amp;lt;&amp;lt; Clone Box;
tempCont &amp;lt;&amp;lt; Close Window;

Column(dt,newX) &amp;lt;&amp;lt; Delete Property("Value Ordering");

// remove the original contingency table and replace with transpose

myr["Contingency Table"][CrossTabBox(1)] &amp;lt;&amp;lt; Delete;
myr["Contingency Table"] &amp;lt;&amp;lt; Append(mycopy);

// show original side by side
obj = Contingency( Y( :Age ), X( :sex ) );

Report(obj)["Contingency Table"] &amp;lt;&amp;lt; Set Title("Contingency Table - Current output");

myr["Contingency Table"] &amp;lt;&amp;lt; Set Title("Contingency Table - Wish List for JMP15");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is anyone else bothered by the orientation of the contingency table and mosaic plot? I do not use it, but one of our JMP users wanted to flip the orientation of the table so that it matches the mosaic plot. Found out that if you swap X and Y, both the table and mosaic plot update. See script below to run an example and compare them side-by-side. It seems you would want the numbers in the table to line up with the cells in the mosaic plot for easier viewing and referencing. I could not find any previous discussions. It appears the contingency table cannot be changed, it is a CrossTabBox, which does not lend itself to changing anything. The script below has in the top part the work around, which is to make a clone of the table made when switching the x and y, and then appending that to the mosaic plot. Also had to do a little with Value Ordering to get it to line up. Will add to the JMP15 wishlist. I did discuss at JMP Discovery Summit with the EA lab and the developers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Found some posts on R language, where you can use the dir() argument and specify the horizontal and vertical, while the "count" output in RStudio stays the same for the orientation.&lt;/P&gt;&lt;P&gt;# R Mosaic Plot Example - Changing Direction&lt;BR /&gt;getwd()&lt;BR /&gt;employee &amp;lt;- read.csv("Products.csv", TRUE, sep = ",",&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; na.strings = TRUE)&lt;BR /&gt;count &amp;lt;- table(employee$EnglishCountryRegionName,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; employee$Color)&lt;BR /&gt;count&lt;BR /&gt;mosaicplot(count, main = "Countries Mosaic Plot",&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sub = "Product Colors by Country",&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xlab = "Colors",&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ylab = "Countries",&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; las = 1,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dir = c("h", "v"),&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; color = "skyblue2",&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; border = "chocolate")&lt;/P&gt;</description>
    <pubDate>Mon, 29 Oct 2018 21:18:13 GMT</pubDate>
    <dc:creator>Vball247</dc:creator>
    <dc:date>2018-10-29T21:18:13Z</dc:date>
    <item>
      <title>Contingency table and mosaic plot are not same orientation</title>
      <link>https://community.jmp.com/t5/Discussions/Contingency-table-and-mosaic-plot-are-not-same-orientation/m-p/81893#M37002</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// For a contingency table report, swap the x and y
// currently can swap the mosaic plot only

Names Default to Here(1);

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
myr = Contingency( Y( :Age ), X( :sex ) );

// Have to have a Contingency Analysis report open
// Can add test to make sure it is open in the future

myr = Current Report();

// taking apart CrossTabBox was easier using XML than JSL

mys = myr["Contingency Table"][CrossTabBox(1)] &amp;lt;&amp;lt; Get XML;

// get current X role or rows of contingency table

start = Contains(mys,"&amp;lt;CrosstabBoxRowsLabel&amp;gt;")+22;
end = Contains(mys,"&amp;lt;/CrosstabBoxRowsLabel&amp;gt;");
newY = Substr(mys,start,end-start);

// get current Y role or cols of contingency table
start = Contains(mys,"&amp;lt;CrosstabBoxColsLabel&amp;gt;")+22;
end = Contains(mys,"&amp;lt;/CrosstabBoxColsLabel&amp;gt;");
newX = Substr(mys,start,end-start);


// Recreate same contingency table but with X and Y flipped
// also temporarily use Value Order to match the Mosaic Plot

myValueLabels = Reverse(Associative Array(Column(dt,newX)) &amp;lt;&amp;lt; Get Keys);
Column(dt,newX) &amp;lt;&amp;lt; Set Property("Value Ordering",myValueLabels);

tempCont = Contingency( Y(Column(dt,newY) ), X(Column(dt,newX) ), Contingency Table );
tempContr = tempCont &amp;lt;&amp;lt; Report;
mycopy = tempContr["Contingency Table"][CrossTabBox(1)] &amp;lt;&amp;lt; Clone Box;
tempCont &amp;lt;&amp;lt; Close Window;

Column(dt,newX) &amp;lt;&amp;lt; Delete Property("Value Ordering");

// remove the original contingency table and replace with transpose

myr["Contingency Table"][CrossTabBox(1)] &amp;lt;&amp;lt; Delete;
myr["Contingency Table"] &amp;lt;&amp;lt; Append(mycopy);

// show original side by side
obj = Contingency( Y( :Age ), X( :sex ) );

Report(obj)["Contingency Table"] &amp;lt;&amp;lt; Set Title("Contingency Table - Current output");

myr["Contingency Table"] &amp;lt;&amp;lt; Set Title("Contingency Table - Wish List for JMP15");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is anyone else bothered by the orientation of the contingency table and mosaic plot? I do not use it, but one of our JMP users wanted to flip the orientation of the table so that it matches the mosaic plot. Found out that if you swap X and Y, both the table and mosaic plot update. See script below to run an example and compare them side-by-side. It seems you would want the numbers in the table to line up with the cells in the mosaic plot for easier viewing and referencing. I could not find any previous discussions. It appears the contingency table cannot be changed, it is a CrossTabBox, which does not lend itself to changing anything. The script below has in the top part the work around, which is to make a clone of the table made when switching the x and y, and then appending that to the mosaic plot. Also had to do a little with Value Ordering to get it to line up. Will add to the JMP15 wishlist. I did discuss at JMP Discovery Summit with the EA lab and the developers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Found some posts on R language, where you can use the dir() argument and specify the horizontal and vertical, while the "count" output in RStudio stays the same for the orientation.&lt;/P&gt;&lt;P&gt;# R Mosaic Plot Example - Changing Direction&lt;BR /&gt;getwd()&lt;BR /&gt;employee &amp;lt;- read.csv("Products.csv", TRUE, sep = ",",&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; na.strings = TRUE)&lt;BR /&gt;count &amp;lt;- table(employee$EnglishCountryRegionName,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; employee$Color)&lt;BR /&gt;count&lt;BR /&gt;mosaicplot(count, main = "Countries Mosaic Plot",&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sub = "Product Colors by Country",&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xlab = "Colors",&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ylab = "Countries",&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; las = 1,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dir = c("h", "v"),&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; color = "skyblue2",&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; border = "chocolate")&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 21:18:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Contingency-table-and-mosaic-plot-are-not-same-orientation/m-p/81893#M37002</guid>
      <dc:creator>Vball247</dc:creator>
      <dc:date>2018-10-29T21:18:13Z</dc:date>
    </item>
  </channel>
</rss>

