How to change color palette of mosaic plot

若如初见. 提交于 2019-11-29 11:10:14

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.

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

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

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

Strategy (2) is implemented as:
set.seed(403)
mosaic(mat, gp = shading_max)

jprockbelly

No really an elegant solution but you can manually define your colours using gpar

mosaic(mat, shade=T, colorize = T, gp = gpar(fill=matrix(c("red","blue","light green", "green", "black","red","brown","white","blue"), 3, 3)))

The next step is to populate the matrix in gpar with sensible colours. There is a pretty good post here about how to assign a colour ramp based on values. https://stackoverflow.com/a/6320940/1502898

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!