gpt4 book ai didi

r - 如何在 r 中命名维度的 "superscriptions"?

转载 作者:行者123 更新时间:2023-12-01 11:46:06 25 4
gpt4 key购买 nike

也许是个愚蠢的问题,但我找不到答案。如果我用 vcd 包制作马赛克图,那么:

 library(vcd)
test<-matrix(c(65,31,495,651), ncol=2,byrow=T)
colnames(test)<-c("2010", "2011")
rownames(test)<-c("yes", "now")
mosaic(test, shade=T, legend=T)

除了多年来的上标和输出(是/否)显示为“A”和“B”之外,它就像一个魅力。

我想命名这些“Years”和“Outputs”,但我找不到相应的参数。我怎么能这样做?提前致谢。

最佳答案

你可以这样指定 dimnames :

dimnames(test) <- list(foo=colnames(test),bar=rownames(test))
mosaic(test, shade=T, legend=T)

enter image description here

事实上,mosaic 更适合应用于列联表,其中标签由 table 函数确定:

color <- sample(c("red","blue"),10,replace=TRUE)
color2 <- sample(c("yellow","green"),10,replace=TRUE)
tab <- table(color,color2)
mosaic(tab, shade=T)

enter image description here

关于r - 如何在 r 中命名维度的 "superscriptions"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15090407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com