Hello,
I'm trying to automate an exploratory analysis as suggested here: Automating exploratory plots with ggplot2 and purrr
i wrote a function that would help me plot relationships between explanatory variables and response variables grouped by demographic variables in color (geom_smooth).
jitter_fun <- function(x, y, z, ...) {
require(tidyverse)
x <- enquo(x)
y <- enquo(y)
z <- enquo(z)
p <- ggplot(data = df, aes(x = !!x, y = !!y)) +
geom_jitter() +
geom_smooth(aes(color = !!z), se = FALSE)
print(p)
}
expl <- c("HH", "A", "empathy", "Extraversion", "Emotionality", "O")
response <- c("courtesy", "noncourtesy", "family", "friend", "selfish", "prosocial")
demo <- c("race", "Gender", "Religion", "Region")
# The function works fine when I enter arguments myself. First image down below.
jitter_fun(HH, overalllie, race)
However, when I run a call that would give me all the plots at once, the regression lines don't appear; in fact, there are no scales indicated on the x and y axes. Second image below.
all_plots = map(demo, ~map(response, ~map(expl, jitter_fun, y = .x)), z = .x)
What can I do to fix this error?