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

tab

ggplot(DatasetB2, aes(x = StudentType, fill = PetOwnership)) +
  geom_bar(position = "dodge") +               
  labs(
    x = "StudentType",
    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)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  tab
## X-squared = 0.040064, df = 1, p-value = 0.8414
cramerV(tab)
## Cramer V 
##  0.04003

The Chi-Square Test of Independence indicated there was not a significant association between StudentID and FavoriteDrink, χ²(297) = 300.00, p = .440. The association between the two variables was weak (Cramer’s V = .04).