cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar

Contingency table and mosaic plot are not same orientation, allow user to change

 

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 JMP wishlist. I did discuss at JMP Discovery Summit 2018 with the EA lab and the developers.

 

 

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.

# R Mosaic Plot Example - Changing Direction
getwd()
employee <- read.csv("Products.csv", TRUE, sep = ",",
                     na.strings = TRUE)
count <- table(employee$EnglishCountryRegionName,
               employee$Color)
count
mosaicplot(count, main = "Countries Mosaic Plot",
           sub = "Product Colors by Country",
           xlab = "Colors",
           ylab = "Countries",
           las = 1,
           dir = c("h", "v"),
           color = "skyblue2",
           border = "chocolate")

// 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)] << Get XML;

// get current X role or rows of contingency table

start = Contains(mys,"<CrosstabBoxRowsLabel>")+22;
end = Contains(mys,"</CrosstabBoxRowsLabel>");
newY = Substr(mys,start,end-start);

// get current Y role or cols of contingency table
start = Contains(mys,"<CrosstabBoxColsLabel>")+22;
end = Contains(mys,"</CrosstabBoxColsLabel>");
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)) << Get Keys);
Column(dt,newX) << Set Property("Value Ordering",myValueLabels);

tempCont = Contingency( Y(Column(dt,newY) ), X(Column(dt,newX) ), Contingency Table );
tempContr = tempCont << Report;
mycopy = tempContr["Contingency Table"][CrossTabBox(1)] << Clone Box;
tempCont << Close Window;

Column(dt,newX) << Delete Property("Value Ordering");

// remove the original contingency table and replace with transpose

myr["Contingency Table"][CrossTabBox(1)] << Delete;
myr["Contingency Table"] << Append(mycopy);

// show original side by side
obj = Contingency( Y( :Age ), X( :sex ) );

Report(obj)["Contingency Table"] << Set Title("Contingency Table - Current output");

myr["Contingency Table"] << Set Title("Contingency Table - Wish List for JMP16");

 

3 Comments
Hegedus1
Level III

There is a simpler solution.

In the Y axis of the mosaic plot select reverse axis.

My request/wish: Make this orientation an option in the contingency platform preferences.

Vball247
Level V

Hi Hegedus1. Great suggestion! But I had to do one more step. When I do the mosaic plot, the Y axis is from 0 to 1 or percentages, but when I click over the Y axis, the Minimum, Maximum, and Reverse Order are greyed out for me, no option to select. I have to select the "Horizontal Mosaic", and then do your suggestion, which can change the order of the one categorical while leaving the cumulative axis alone. That lines up with the table below it finally.

 

Contingency(
	Y( :age ),
	X( :sex ),
	Contingency Table,
	Horizontal Mosaic( 1 ),  // swap the axes
	SendToReport( Dispatch( {"Mosaic Plot"}, "1", ScaleBox, {Reversed Scale} ) ) // reverse the categories to match table
);

 

Status changed to: Acknowledged

Hi @Vball247, thank you for your suggestion! We have captured your request and will take it under consideration.