data(fortune)
head(fortune)
##   wealth age region
## 1   37.0  50      M
## 2   24.0  88      U
## 3   14.0  64      A
## 4   13.0  63      U
## 5   13.0  66      U
## 6   11.7  72      E
str(fortune)
## 'data.frame':    232 obs. of  3 variables:
##  $ wealth: num  37 24 14 13 13 11.7 10 8.2 8.1 7.2 ...
##  $ age   : int  50 88 64 63 66 72 71 77 68 66 ...
##  $ region: Factor w/ 5 levels "A","E","M","O",..: 3 5 1 5 5 2 3 5 5 2 ...

Assessment 1

ggplot(aes(x = age, y = wealth), data = fortune) + 
    geom_point(aes(color = region))  + 
    geom_vline(xintercept = 64.03) +
    geom_hline(yintercept = 2.60) +
    theme_bw()
## Warning: Removed 7 rows containing missing values (geom_point).

Assessment 2

ggplot(aes(x = age, y = wealth, group = region), data = fortune) + 
    geom_point(aes(color = region)) +
    geom_smooth(aes(color = region),  se = FALSE) + 
    facet_wrap(~region, ncol = 1) +
     theme_bw()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 7 rows containing non-finite values (stat_smooth).
## Warning: Removed 7 rows containing missing values (geom_point).

Assessment 3

data(happy)
str(happy)
## 'data.frame':    39 obs. of  5 variables:
##  $ happy: num  10 8 8 8 4 9 8 6 5 4 ...
##  $ money: num  36 47 53 35 88 175 175 45 35 55 ...
##  $ sex  : num  0 1 0 1 1 1 1 0 1 1 ...
##  $ love : num  3 3 3 3 1 3 3 2 2 1 ...
##  $ work : num  4 1 5 3 2 4 4 3 2 4 ...
happy$sex <- as.factor(happy$sex)
happy$love <- as.factor(happy$love)
ggplot(aes(x = happy),  data = happy) +
    geom_density(aes(fill = love), alpha = 0.5) +
    theme_bw()

Assessment 4

ggplot(aes(x = love, y = happy), data = happy) +
    geom_point(position = "jitter") +
    geom_boxplot(aes(fill = sex)) +
    theme_bw()

Assessment 5

happy$sex <- as.factor(happy$sex)
happy$love <- as.numeric(happy$love)
str(happy)
## 'data.frame':    39 obs. of  5 variables:
##  $ happy: num  10 8 8 8 4 9 8 6 5 4 ...
##  $ money: num  36 47 53 35 88 175 175 45 35 55 ...
##  $ sex  : Factor w/ 2 levels "0","1": 1 2 1 2 2 2 2 1 2 2 ...
##  $ love : num  3 3 3 3 1 3 3 2 2 1 ...
##  $ work : num  4 1 5 3 2 4 4 3 2 4 ...
ggplot(happy, aes(x = love, y = happy, color = sex)) +
  geom_point(position = "jitter") + 
  geom_smooth(method = lm) +
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'