0

So, I'm trying to make a plot in the following format:

print(levelplot(Z ~ X*Y, data=data))

X and Y are column names in the dataframe. If I have a list of the column names, how can I go through them and plot every column against every other column?

1 Answer 1

1

If you have a vector of colnames, say cols, you can loop over all the combinations of those column names, each time creating the plot, like this:

plots = lapply(combn(cols,2,simplify = F), function(v) {
  levelplot(as.formula(paste0("Z~",v[1],"*",v[2])), data=d)
})

Now, plots is a list of levelplot() objects, which you can then plot, for example, like this:

gridExtra::grid.arrange(plots[[1]], plots[[2]])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.