马赛克图,每个框中带有标签,显示所有观测值的名称和百分比 [英] Mosaic plot with labels in each box showing a name and percentage of all observations

查看:182
本文介绍了马赛克图,每个框中带有标签,显示所有观测值的名称和百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个镶嵌图(R包VCD,请参见例如 http://cran.r-project.org/web/packages/vcd/vignettes/residual-shadings.pdf ),并在图中添加标签.标签应显示各种因素的组合或某些自定义标签,以及在此类别组合中总观测值的百分比(请参见例如

I would like to create a mosaic plot (R package vcd, see e.g. http://cran.r-project.org/web/packages/vcd/vignettes/residual-shadings.pdf ) with labels inside the plot. The labels should show either a combination of the various factors or some custom label and the percentage of total observations in this combination of categories (see e.g. http://i.usatoday.net/communitymanager/_photos/technology-live/2011/07/28/nielsen0728x-large.jpg , despite this not quite being a mosaic plot). I suspect something like the labeling_values function might play a role here, but I cannot quite get it to work.

library(vcd)
library(MASS)
data("Titanic")
mosaic(Titanic, labeling = labeling_values)

也欢迎以非统计人员友好的方式用分类数据表示两个变量的替代方法,并且是可接受的解决方案.

Alternative ways to represent two variables with categorical data in a friendly way for non-statisticians are also welcome and are acceptable solutions.

推荐答案

以下是添加比例作为标签的示例.通常,地块的定制程度取决于品味,但这至少表明了原理.参见?labeling_cells,了解更多可能性.

Here is an example of adding proportions as labels. As usual, the degree of customization of a plot is a matter of taste, but this shows at least the principles. See ?labeling_cells for further possibilities.

labs <- round(prop.table(Titanic), 2)
mosaic(Titanic, pop = FALSE)
labeling_cells(text = labs, margin = 0)(Titanic)

这篇关于马赛克图,每个框中带有标签,显示所有观测值的名称和百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆