Is there an R Function to add a scale/ axis to a mosaic plot

350 Views Asked by At

Im trying to make a mosaic plot and it currently looks like this. It does not have an axis for some reason even though I have data and added the variables already. I was wondering if someone knew how to do this? Thanks

enter image description here

assignment$pet <- ifelse(assignment$pet == 0, "no", "yes")
mosaicplot(~ pet + change, 
           data = assignment, 
           color = TRUE, las = 1, 
           xlab="Ownership of pets", 
           ylab="Degree of connectivity", 
           main="The degree of change in social connectivity vs the ownership of pets")

I edited the change variable like this:

knitr::opts_chunk$set(echo = TRUE)
assignment$change[assignment$time1<assignment$time2]<-"increase"
assignment$change[assignment$time1>assignment$time2]<-"decrease"
assignment$change[assignment$time1==assignment$time2]<-"no change"

the spreadsheet file looks like this btw

enter image description here

1

There are 1 best solutions below

0
On

The spineplot() function in R is a special flavor of mosaic plot that shades by the "dependent" variable and also adds a second y-axis with the corresponding cumulative proportions:

spineplot(change ~ pet, data = assignment)