简体   繁体   English

如何禁用镶嵌图中的y轴?

[英]How to disable y-axis in mosaic plot?

How to disable y-axis in mosaic plot? 如何禁用镶嵌图中的y轴

Example: 例:

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"))

I would like to use own axis function. 我想使用自己的轴功能。 So how can I remove the y axis names? 那么如何删除y轴名称? Usually something like yaxt="n" works, but not it this case. 通常像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)

There doesn't seem to be a way to do it directly from the mosaicplot function but there is an easy alternative. 似乎没有直接从mosaicplot函数直接执行此操作的方法,但是有一个简单的替代方法。

Just turn the tab.dat row names to '' and this will work fine 只需将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") )

Seems like an easy to do hack. 似乎很容易破解。 Maybe this is why the developers didn't include it as an argument in mosaicplot . 也许这就是为什么开发人员没有将它作为参数包含在mosaicplot

Output: 输出:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM