// 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 JMP15");是否還有其他人對列聯表和馬賽克情節的方向感到困擾?我不使用它,但我們的一個JMP用戶想要翻轉表格的方向,使其與馬賽克圖表相匹配。發現如果你交換X和Y,表格和馬賽克圖都會更新。請參閱下面的腳本以運行示例並將它們並排比較。您似乎希望表格中的數字與馬賽克圖中的單元格對齊,以便於查看和參考。我找不到任何先前的討論。似乎偶然表不能改變,它是一個CrossTabBox,它不適合改變任何東西。下面的腳本在頂部有解決方法,即在切換x和y時復製表格,然後將其附加到馬賽克圖表中。還必須通過Value Ordering做一點才能讓它排成一行。將添加到JMP15願望清單。我在EA實驗室和開發人員的JMP Discovery Summit上進行了討論。
在R語言上找到一些帖子,你可以使用dir()參數並指定水平和垂直,而RStudio中的“count”輸出對於方向保持相同。
#R馬賽克圖示例 - 改變方向
getwd()
employee < - read.csv(“Products.csv”,TRUE,sep =“,”,
na.strings = TRUE)
count < - table(employee $ EnglishCountryRegionName,
員工$顏色)
計數
mosaicplot(count,main =“國家馬賽克圖”,
sub =“按國家/地區劃分的產品顏色”,
xlab =“顏色”,
ylab =“國家”,
las = 1,
dir = c(“h”,“v”),
color =“skyblue2”,
border =“chocolate”)