0

I am using Iris dataset in R.

I have the following code

for (i in colnames(iris[-5])) { plot(iris$Species, iris[[i]], xlab = 'Species', ylab = `i`) } 

This prints out 4 boxplot. I want to do the same in ggplot with the following code

for (i in colnames(iris[-5])) { print(iris %>% ggplot(aes(x = Species)) + geom_col(aes(y = i))) } 

When I do this in ggplot, the boxplots look messed up. Is it just my R or am I missing something?

1
  • 3
    Welcom to the wonderful world of tidyverse non-standard evaluation (NSE). I think geom_boxplot(aes(y = !!sym(i)))) will give you what you want, after correcting the obvious typo in your code. By the way "look messed up" isn't terribly helpful. Please be more specific. Commented Jun 12, 2022 at 11:57

1 Answer 1

0

In this case, you can just change aes(y=i) to aes_string(y=i), and of course, use geom_boxplot instead of geom_col

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.