# Filter the data to only include loans paid off
was_paid <- subset(loan_data, loan_status == "PAIDOFF" | loan_status == "COLLECTION_PAIDOFF")
# Filter the data to only include loans not paid off
was_not_paid <- subset(loan_data, loan_status == "COLLECTION")
# Summarize data by terms and count the number of paid off loans
paid_off_count <- was_paid %>%
group_by(terms) %>%
summarise(paid_off = n())
# Summarize data by terms and count the number of not paid off loans
not_paid_off_count <- was_not_paid %>%
group_by(terms) %>%
summarise(not_paid_off = n())
# Create plot for paid off loans
p1 <- ggplot(paid_off_count, aes(x = as.factor(terms), y = paid_off)) +
geom_col(fill = "blue") +
labs(title = "Paid Off Loans", x = "Terms", y = "Count") +
scale_x_discrete(labels = c("7", "15", "30"))
# Create plot for non paid off loans
p2 <- ggplot(not_paid_off_count, aes(x = as.factor(terms), y = not_paid_off)) +
geom_col(fill = "red") +
labs(title = "Not Paid Off Loans", x = "Terms", y = "Count") +
scale_x_discrete(labels = c("7", "15", "30"))