2015-07-05 60 views
2

如何在馬賽克圖中禁用y軸如何禁用馬賽克圖中的y軸?

實施例:

x <- data.frame(o=c(rep("AAAAAAAAAAAAAAAAAAA",50),rep("BBBBBBBBBBBBBBBBBBBBBBBBBBBBB",40),rep("CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",70)),r=runif(160)) 
x$int <- findInterval(x$r, seq(0.1,1,0.1), rightmost.closed = TRUE, all.inside = TRUE) 

tab.dat <- with(x, table(o, int)) 

par(mar=c(3, 3, 3, 3)) 
mosaicplot(tab.dat, col=colorRampPalette(c("green3", "yellow", "red"), space="rgb")(9), las=2, dir=c("h","v")) 

我想用自己的軸的功能。那麼我怎麼去除y軸的名字呢?通常像yaxt="n"有效,但不是這種情況。

axis(2, at=seq(0, 1, by = 1/(length(rownames(tab.dat)) - 1)), labels=rownames(tab.dat), cex.axis=2.2, line=1.1, las=1) 

回答

3

似乎有不是一個辦法直接從mosaicplot功能做到這一點,但有一個很不錯的選擇。

只要打開tab.dat行名稱'',這將很好地工作

tab.dat <- with(x, table(o, int)) 

#I am only adding this line of code below 
#just use the row.names function to set the names to '' 
row.names(tab.dat) <- rep('',3) 

par(mar=c(3, 3, 3, 3)) 
mosaicplot(tab.dat, col=colorRampPalette(c("green3", "yellow", "red"), space="rgb")(9), las=2, dir=c("h","v")) 

似乎是一個容易破解做到。也許這就是爲什麼開發者沒有在mosaicplot中將它作爲參數的原因。

輸出:

enter image description here