Extramarital Affairs Data

Introduction

The data I decided to look at and explore ggplot with was from the Ecdat library in R Studio. The data set is called Fair. This data came from a survey done from two magazine in 1969 and 1974. It contains the following variables:

Research Questions:

The results I believe we may find, after using ggplot to explore the date , would probably show age and how religious a person is to be contributing variables as to whether or not a married person has an affair. I don’t think we are going to see that big of a difference between males and females and I don’t think the number of years married will matter either. One issue with this data that may hinder some of our results is that since this is comning from two different surveys, one survey had 601 observations and the other had 6,366. This survey was distributed around the entire US.

p <- ggplot(Fair, aes(x = ym, y = nbaffairs)) +
  geom_line(aes(color = sex), size = 2) +
  ggtitle("Number of Affairs from Married Persons in Past Year")
p

p + theme_tufte()

p2<- ggplot(Fair, aes(x = nbaffairs)) +
  geom_bar(aes(fill = sex), size = 2) +
  ggtitle("Number of Affairs from Married Persons in Past Year")
p2

p3<- ggplot(Fair, aes(x = ym)) +
  geom_bar(aes(color = sex), size = 2) +
  ggtitle("Number of Years Married")
p3

p4<- ggplot(Fair, aes(x = ym, y= nbaffairs)) +
  geom_point(aes(color = sex), size = 3) +
  ggtitle("Number of Affairs from Married Persons in Past Year")
p4

p41 <- p4 + geom_point() + stat_quantile()
p41

p5<- ggplot(Fair, aes(x = rate)) +
  geom_bar(aes(fill= sex), size = 2) +
  ggtitle("Self Rating of Marriage")
p5

p6<- ggplot(Fair, aes(x = religious)) +
  geom_bar(aes(fill = sex), size = 2) +
  ggtitle("Self Rating of How Religious")
p6

Using Mosaic

ggplot(data = Fair) +
   geom_mosaic(aes(weight = ym, x = product(nbaffairs), fill=factor(nbaffairs)), na.rm=TRUE) +
   labs(x="Number of Affiars from Married Persons ", title='f(nbaffairs)') + guides(fill=guide_legend(title = "nbaffairs", reverse = TRUE))

ggplot(data = Fair) +
   geom_mosaic(aes(weight = ym, x = product(nbaffairs, age), fill=factor(nbaffairs)), na.rm=TRUE) +    theme(axis.text.x=element_text(angle=-25, hjust= .1)) + labs(x="age ", title='f(nbaffairs | age) f(age)') + guides(fill=guide_legend(title = "nbaffairs", reverse = TRUE))

 ggplot(data = Fair) +
   geom_mosaic(aes( x = product(nbaffairs, age), fill=factor(nbaffairs), conds=product(sex)), na.rm=TRUE, divider=mosaic("v")) +    theme(axis.text.x=element_text(angle=-25, hjust= .1)) + labs(x="age ", title='f(nbaffairs, age | sex)') + facet_grid(sex~.)  + guides(fill=guide_legend(title = "nbaffairs", reverse = TRUE))

Number of Affairs, Years Married by Gender

library(ggforce)


ggplot(Fair, aes(nbaffairs, ym, colour = sex)) +
    geom_point() +
    facet_zoom(x = sex == "versicolor")

Number of Years Married

library(ggplot2)
library(gridExtra)
library(ggalt)


ggplot(Fair, aes(x=ym)) + 
  stat_bkde(alpha=1/2)

Self Rating on How Religious During Marriage

Rating of Marriage

ggplot(Fair, aes(x=rate)) + 
  stat_bkde(alpha=1/2)