A mosaic plot is a type of graphical display that is used to visualize the relationship between two or more categorical variables. It is similar to a contingency table, but it uses areas rather than counts to show the proportions or frequencies of each combination of variables.
Create a mosaic example for the amount of people that are believers in the UFOs in 6 different cities.
We have the 6 rows with the number of habitants that they either believe a lot, or somewhere in the middle, or not at all.
# creating a random dataset
# creating 6 rows
data_values <- matrix(c(34, 34, 34,
20, 35, 5,
60, 10, 5,
9, 12, 45,
65, 34, 20,
50, 20, 32))
# creating dataset with above values
data <- as.table(
matrix(
data_values,
# specifying the number of rows
nrow = 6,
byrow = TRUE,
# creating two lists one for rows
# and one for columns
dimnames = list(
city = c('A','B','C', 'D', 'E', 'F'),
believers = c('yes', 'so and so', 'very')
)
)
)
# plotting the mosaic chart
mosaic(data,
# shade is used to plot colored chart
shade=TRUE,
# adding title to the chart
main = "Believe or not"
)

No comments:
Post a Comment