This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
The embedded code chunk below creates to tables that can be used as parameters for mosaicplot().
Mosasic plots are normally used to view proportions in contingency tables. Since the supplied data aren’t the result of sampling, statistical inference from these tables is not valid.
countana <- c(1,0,1,1,2,1,3,4,2,3,9,32,90,71,54,9,134,664,531,209,142,173,437,436,91)
mtrxana <- matrix(countana,ncol=5,byrow=TRUE)
rownames(mtrxana) <- c("5", "4", "3", "2", "1")
colnames(mtrxana) <- c("A", "B", "C", "D", "E")
ctableana <- as.table(mtrxana)
countmtz <- c(3,1,0,2,4,8,29,55,14,22,15,87,418,728,340,41,28,154,821,939,3,21,78,257,594)
mtrxmtz <- matrix(countmtz,ncol=5,byrow=TRUE)
rownames(mtrxmtz) <- c("5", "4", "3", "2", "1")
colnames(mtrxmtz) <- c("A", "B", "C", "D", "E")
ctablemtz <- as.table(mtrxmtz)
Mosiac and Spine plots of the supplied data. Mosaic plots are generally used when there are more than 2 factors. In this case, there are two factors - consequence and frequency - with five levels each.
mosaicplot(ctableana, main = "Anacortes RBWS")
mosaicplot(ctablemtz, main = "Martinez RBWS")
spineplot(ctableana, xlab = "Frequency", ylab = "Consequence", main = "Anacortes RBWS")
spineplot(ctablemtz, xlab = "Frequency", ylab = "Consequence", main = "Martinez RBWS")
Anacortes RBWS Proportions
round(addmargins(100*prop.table(mtrxana)), 1)
## A B C D E Sum
## 5 0.0 0.0 0.0 0.0 0.1 0.2
## 4 0.0 0.1 0.1 0.1 0.1 0.4
## 3 0.3 1.0 2.9 2.3 1.7 8.3
## 2 0.3 4.3 21.4 17.1 6.7 49.9
## 1 4.6 5.6 14.1 14.1 2.9 41.3
## Sum 5.2 11.0 38.6 33.6 11.6 100.0
Martinez RBWS Proportions
round(addmargins(100*prop.table(mtrxmtz)), 1)
## A B C D E Sum
## 5 0.1 0.0 0.0 0.0 0.1 0.2
## 4 0.2 0.6 1.2 0.3 0.5 2.7
## 3 0.3 1.9 9.0 15.6 7.3 34.1
## 2 0.9 0.6 3.3 17.6 20.1 42.5
## 1 0.1 0.5 1.7 5.5 12.7 20.4
## Sum 1.5 3.6 15.1 39.1 40.7 100.0