This repository has been archived by the owner on May 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
OKcupidata.R
49 lines (42 loc) · 2 KB
/
OKcupidata.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
library(gganimate)
library(tidyverse)
library(okcupiddata)
library(icon)
data(profiles)
profiles_red <- profiles %>% select(pets, sex, status, sign)
profiles_red <- profiles_red %>% mutate(sign = str_extract(sign, "[a-z']+[[:space:]]"))
profiles_red <- profiles_red %>%
mutate(pets_dislike = case_when(
str_detect(pets, "dislikes dogs and dislikes cats") ~ "dogs/cats",
str_detect(pets, "dislikes dogs") ~ "dogs",
str_detect(pets, "dislikes cats") ~ "cats"))
profiles_red <- profiles_red %>% mutate(sign = gsub(" ", "", sign))
profiles_red <- profiles_red %>%
mutate(pets_like = case_when(
str_detect(pets, "likes dogs and likes cats") ~ "dogs/cats",
str_detect(pets, "likes dogs") ~ "dogs",
str_detect(pets, "likes cats") ~ "cats"))
profiles_red <- profiles_red %>%
mutate(pets_has = case_when(
str_detect(pets, "has dogs and has cats") ~ "dogs/cats",
str_detect(pets, "has dogs") ~ "dogs",
str_detect(pets, "has cats") ~ "cats"))
# define factor
profiles_red <- profiles_red %>% filter(!is.na(sign))
profiles_red <- profiles_red %>%
mutate(sign = factor(sign, levels=c("aries", "taurus", "gemini", "cancer",
"leo", "virgo", "libra", "scorpio",
"sagittarius", "capricorn", "aquarius",
"pisces")))
profiles_red %>%
write.csv("profiles_red.csv")
# start with easy ggplot
ggplot(profiles_red, aes(x =pets_dislike)) + geom_bar() + facet_grid(~ sign)
ggplot(profiles_red, aes(x =pets_like)) + geom_bar() + facet_grid(~ sign)
ggplot(profiles_red, aes(x =pets_has)) + geom_bar() + facet_grid(~ sign)
dislike_plot <- ggplot(profiles_red, aes(x =pets_dislike)) + geom_bar()
dislike_plot + transition_manual(sign)
like_plot <- ggplot(profiles_red, aes(x =pets_like)) + geom_bar()
like_plot + transition_manual(sign) + labs(title="{current_frame}")
has_plot <- ggplot(profiles_red, aes(x =pets_has)) + geom_bar()
has_plot + transition_manual(sign) + labs(title="{current_frame}")