-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.R
67 lines (45 loc) · 1.63 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
# INSTALL GGCATS PACKAGE AND ECDAT
install.packages("remotes")
remotes::install_github("R-CoderDotCom/ggcats@main")
install.packages("Ecdat")
# LOAD LIBRARIES
library(ggplot2)
library(ggcats)
library(tidyverse)
library(gganimate)
# VISUALIZE AVAILABLE CATS
theGrid <- expand.grid(1:5, 3:1)
dataFrame <- data.frame(x = theGrid[, 1],
y = theGrid[, 2],
image = c("shironeko", "venus", "hipster", "lil_bub", "maru",
"colonel", "grumpy", "mouth", "pop", "pop_close",
"pusheen", "pusheen_pc", "toast", "bongo", "nyancat"))
ggplot(dataFrame) +
geom_cat(aes(x, y, cat = image), size = 4) +
xlim(c(0.30, 5.5)) +
ylim(c(0.30, 3.5))
# TESTING PUSHEEN CAT AND MARU CAT
ggplot(mtcars) +
geom_cat(aes(mpg, wt), cat = "pusheen", size = 4)
ggplot(mtcars) +
geom_cat(aes(mpg, wt, size = cyl), cat = "maru")
# EXAMPLE GGCAT WITH GGANIMATE
library(Ecdat)
data(incomeInequality)
newData <-
incomeInequality %>%
select(Year, P99, median) %>%
rename(income_median = median,
income_99percent = P99) %>%
pivot_longer(cols = starts_with("income"),
names_to = "income",
names_prefix = "income_")
newData$cat <- rep(NA, 132)
newData$cat[which(newData$income == "median")] <- rep(c("pop_close", "pop"), 33)
newData$cat[which(newData$income == "99percent")] <- "bongo"
ggplot(newData, aes(x = Year, y = value, group = income, color = income)) +
geom_line(size = 2.5) +
labs(title="Testing ggcats with gganimate",
subtitle = "Pop cat and Bongo cat") +
geom_cat(aes(cat = cat), size = 6) +
transition_reveal(Year)