library(readxl)
library(ggplot2)
library(rcompanion)
DatasetB2 <- read_excel("C:/Users/user/Downloads/DatasetB2.xlsx")
tab <- table(DatasetB2$StudentType, DatasetB2$PetOwnership)

ggplot(DatasetB2, aes(StudentType,fill = StudentID )) + geom_bar() + labs(

  x = "PetOwnership",
  y = "frequency",
  title = "petownership by  StudentType"
) +
  theme(
    text = element_text(size = 14),
    axis.title = element_text(size = 14),
    axis.text = element_text(size = 14),
    plot.title = element_text(size = 14),
    legend.position = "none"
    
  ) 

chisq.test(tab)

#The Chi-Square Test of Independence indicated there was not a significant association between Petownership and StudentType, χ²(1) = 0.040064, df = 1, p-value = 0.8414 . The association between the two variables was strong.