如何更改马赛克图的调色板 [英] How to change color palette of mosaic plot

查看:219
本文介绍了如何更改马赛克图的调色板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据和代码:

> mat <- matrix(c(120,230,84,70,130,83,13,26,18),3)
> dimnames(mat) <- list(c("good","fair","poor"),c("a","b","c"))
> mat

> mat
       a   b  c
good 120  70 13
fair 230 130 26
poor  84  83 18
> 
> chisq.test(mat)

        Pearson's Chi-squared test

data:  mat
X-squared = 11.411, df = 4, p-value = 0.02231

> library(vcd)
> mosaic(mat, shade=T)

卡方检验显示出显着差异,但由于残差很小,因此未看到颜色.具有较高的残差,可以看到颜色:

The chi-squared test shows significant difference but no color is seen since residuals are small. With higher residuals, colors are seen:

?mosaic显示此信息:

?mosaic shows this information:

highlighting_fill: color vector or palette function used for a highlighted variable, if any.

如何更改上述图的填充颜色?

How can I change fill color for above plot?

推荐答案

默认情况下,如建议的那样,vcd中的马赛克图的阴影将截止点2和4用作与每个像元相关联的残差的绝对值由Friendly(1994,美国统计协会杂志 89 ,第190-200页).其背后的想法是,如果模型拟合得当(由于残差的近似正态性),则这些临界值应与大约5%和0.01%相交.但是,这些截止值对应于细胞的个体显着性,而卡方检验评估的是总体的显着性.

By default, the shading of mosaic plots in vcd uses the cut-offs 2 and 4 for the absolute value of the residuals associated with each cell as suggested by Friendly (1994, Journal of the American Statistical Association, 89, 190-200). The idea behind this is that these cut-offs should be crossed with approximately 5% and 0.01% if the model fits well (due to the approximate normality of the residuals). However, these cut-offs corresponds to individual significance of the cells while the chi-squared test assesses overall significance.

有两种策略可以解决此问题:(1)由于Friendly(1994)阴影旨在产生偏差的模式,而不是直接对应于重要性 em>,您可以简单地将截止值修改为对给定表有效的较低值(例如,此处为1和1.8). (2)切换到最大绝对残差(而不是它们的平方和)的测试,以便可以对在某些显着性水平(例如10%和1%)下显着的所有像元进行阴影处理.两种策略都在vcd中实现,并在?shading_hcl的示例中进行了说明(使用与mat具有非常相似的属性的示例). Zeileis,Meyer,Hornik(2007)对基本思想进行了解释. 可视化(条件)独立性的基于残差的阴影",计算和图形统计杂志 16 (3),507-525. doi:10.1198/106186007X237856

There are two strategies to deal with this: (1) As the Friendly (1994) shading is intended to bring out the pattern of deviation rather than to correspond directly to significance, one can simply modify the cut-offs to lower values that work well for a given table (e.g., 1 and 1.8 here). (2) Switch to a test of the maximum absolute residuals (rather than their sum of squares) so that all cells that are significant at certain significance levels (e.g., 10% and 1%) can be shaded. Both strategies are implemented in vcd and illustrated in the examples of ?shading_hcl (using an example with very similar properties to your mat). The underlying ideas are explained in Zeileis, Meyer, Hornik (2007). "Residual-Based Shadings for Visualizing (Conditional) Independence", Journal of Computational and Graphical Statistics, 16(3), 507-525. doi:10.1198/106186007X237856

可以通过以下方法将策略(1)应用于您的数据:

Strategy (1) can be applied to your data by:

mosaic(mat, gp = shading_hcl, gp_args = list(interpolate = c(1, 1.8)))

策略(2)的实现方式为:

Strategy (2) is implemented as:

set.seed(403)
mosaic(mat, gp = shading_max)

这篇关于如何更改马赛克图的调色板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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