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 ...
ggplot(aes(x = age, y = wealth, color = region), data = fortune) + 
 geom_point()  + 
  geom_vline(xintercept = 64.03) +
  geom_hline(yintercept = 2.5)

ggplot(aes(x = age, y = wealth, group = region), data = fortune) + 
  geom_point(aes(color = region)) +
  geom_smooth(aes(color = region), data = filter(fortune, region == "A"), se = FALSE) +
  geom_smooth(aes(color = region),data = filter(fortune, region == "E"), se = FALSE) +
  geom_smooth(aes(color = region),data = filter(fortune, region == "M"), se = FALSE) +
  geom_smooth(aes(color = region),data = filter(fortune, region == "O"), se = FALSE) +
  geom_smooth(aes(color = region),data = filter(fortune, region == "U"), se = FALSE) +
  facet_wrap(~ region, nrow = 5)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

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(colour = "black", aes(fill = love), alpha=.5)

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

ggplot(happy, aes(x = as.numeric(love), y = as.numeric(happy), color = sex)) +
  geom_smooth(aes(color = sex), method = "lm",se = FALSE) +
  geom_point(position = "jitter") +
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'