This is a dataset that was previously used and was found on kaggle.com. I want to re-visit the data and graph the information to see what type of story can be concluded from it.
library(ggplot2)
library(ggthemes)
library(Zelig)
library(ggrepel)
library(HistData)
library(tidyverse)
library(dplyr)
options(dplyr.show_progress = FALSE)
affairs<- read.csv("C:/Users/Jessica/Desktop/712/affairs.csv")
head(affairs)
## affairs gender age yearsmarried children religiousness education
## 1 0 male 37 10.00 no 3 18
## 2 0 female 27 4.00 no 4 14
## 3 0 female 32 15.00 yes 1 12
## 4 0 male 57 15.00 yes 5 18
## 5 0 male 22 0.75 no 2 17
## 6 0 female 32 1.50 no 2 17
## occupation rating
## 1 7 4
## 2 6 4
## 3 1 4
## 4 6 5
## 5 6 3
## 6 5 5
g1 <- ggplot(affairs, aes(x = gender)) + geom_bar(color ="Blue", fill = "Blue")
gender <- g1 + labs(title = "Gender Count") + ylab("Count") + xlab("Gender")
plot(gender)
affairs <- affairs%>%
mutate(age_group=ifelse(age >= 17 & age <= 25, "17-25 years old",
ifelse(age >=26 & age <= 35, "26-35 years old",
ifelse(age>= 36 & age <= 45, "36-45 years old",
ifelse(age >=46 & age <= 55, "46-55 years old",
ifelse(age>=56, "56-65 years old", NA))))))
g <- ggplot(affairs, aes(x = age_group)) + geom_bar(color ="Blue", fill = "Red")
ggplotagegroup <- g + labs(title = "Affairs by Age Group") + ylab("Count") + xlab("Age Group")
plot(ggplotagegroup)
Focusing on The Number of Years Married
g1 <- ggplot(affairs, mapping = aes(x = yearsmarried, y = affairs))
g2 <- g1 + geom_bin2d()+ggtitle("Years Married vs. Number of Affairs")
g2
g3 <- g1 + geom_smooth() +ggtitle("Years Married vs. Number of Affairs")
g3
qplot(yearsmarried, data = affairs, fill = gender, ylab = "Affairs", xlab = " Years Married ") + scale_fill_manual("gender", values = c("male" = "blue", "female" = "orange"))
qplot(religiousness, data = affairs, fill = gender, ylab = "Affairs", xlab = " Religiousness") + scale_fill_manual("gender", values = c("male" = "red", "female" = "green"))
qplot(rating, data = affairs, fill = gender, ylab = "Affairs", xlab = " Rating") + scale_fill_manual("gender", values = c("male" = "red", "female" = "blue"))
qplot(rating, affairs, data = affairs, colour = gender)