-
Notifications
You must be signed in to change notification settings - Fork 0
/
ROAM_exp.R
37 lines (33 loc) · 1.13 KB
/
ROAM_exp.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
# grouped AVG -
# uses tidyeval from dplyr 0.6
grpPlot_AVG <- function(dataset,grpVar,comVar){
grpVar <- enquo(grpVar)
comVar <- enquo(comVar)
com_name <- paste0("mean_",comVar)[2]
dataset %>%
group_by(!!grpVar) %>%
nest() %>%
mutate(plot = map2(data, !!grpVar, ~ggplot(data=dataset,
aes_string(rlang::quo_text(grpVar),
rlang::quo_text(comVar))) +
geom_point()
))
}
# grouped XY -
# uses tidyeval from dplyr 0.6
grpPlot_XY <- function(dataset,grpVar,xVar,yVar){
grpVar <- enquo(grpVar)
xVar <- enquo(xVar)
yVar <- enquo(yVar)
dataset %>%
group_by(!!grpVar) %>%
nest() %>%
mutate(plot = map2(data, !!grpVar, ~ggplot(data=.x,
aes_string(rlang::quo_text(xVar),
rlang::quo_text(yVar))) +
geom_point()
))
}
# in conjuction with map2
# grouped_XY <- grpPlot_XY(dataset = small_pwt,country,pop,avh)
# map2(paste0(qC$country, ".pdf"), qC$plot, ggsave)