I have a binary outcome and several predictors. I need a series of ggplots and would rather not have to type them all out. I just finished figuring out how to loop glm's, but ggplot is giving me more trouble. How can I do this?
data:
ID | outcome | x1 | x2 | x3 |
---|---|---|---|---|
1 | 1 | 6 | Blah | Y |
2 | 0 | 1 | Dee | N |
3 | 1 | 3 | Bleh | N |
Tedious code:
p1 = ggplot(data, aes(x = x1, fill = outcome)) + geom_bar(position = "dodge")
p1
p2 = ggplot(data, aes(x = x2, fill = outcome)) + geom_bar(position = "dodge")
p2
p3 = ggplot(data, aes(x = x3, fill = outcome)) + geom_bar(position = "dodge")
p3