Professional Documents
Culture Documents
Q13 - Binary Data
Q13 - Binary Data
library(ggplot2)
library(dplyr)
library(reshape2)
library(vcd)
# Data
data <- data.frame(
ID = c(1, 2, 3, 4, 5),
Variable1 = c(0, 1, 0, 1, 0),
Variable2 = c(1, 0, 1, 1, 0),
Variable3 = c(0, 1, 1, 0, 0)
)
# 1. Create a bar plot showing the count of each value (0 or 1) for Variable1
ggplot(data, aes(x = as.factor(Variable1))) +
geom_bar(fill = "skyblue", color = "black") +
ggtitle("Bar Plot of Variable1 Values") +
xlab("Variable1") +
ylab("Count") +
scale_x_discrete(labels = c("0", "1")) +
theme_minimal()