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"
    
  ) 
## Warning: The following aesthetics were dropped during statistical transformation: fill.
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
##   the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
##   variable into a factor?

chisq.test(tab)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  tab
## X-squared = 0.040064, df = 1, p-value = 0.8414

#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.