Loop to automate the plotting process in R

0 votes
Plotting can sometime get hectic. Is there a way to automate it?
Dec 6, 2018 in Data Analytics by Ali
• 10,450 points
28 views

1 answer to this question.

0 votes

Try something like this:

library(tidyverse)
data(iris)

## create a grid with variable combinations
var <- iris %>%
  select(everything(), -Species) %>%
  names() %>%
  expand.grid(x = ., y =., stringsAsFactors = F)

##create plotting function
plot_data <- function(data, x, y){
  ggplot(data, aes_string(x, y)) +
           geom_point() +
    ggtitle(paste(x, "vs", y))
}

map2(.x = var$x,
     .y = variables$y,
     .f = ~ plot_data(iris, .x, .y))
answered Dec 6, 2018 by Maverick
• 10,040 points

Related Questions In Data Analytics

0 votes
1 answer

Plotting multiple graphs on the same page in R

If you want to plot 4 graphs ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,550 points
44 views
0 votes
1 answer

How to find out the sum/mean for multiple variables per group in R?

You can use the reshape2 package for ...READ MORE

answered Apr 12, 2018 in Data Analytics by DataKing99
• 8,100 points
305 views
0 votes
1 answer
0 votes
1 answer

Which function can I use to clear the console in R and RStudio ?

Description                   Windows & Linux           Mac Clear console                      Ctrl+L ...READ MORE

answered Apr 17, 2018 in Data Analytics by anonymous
1,090 views
0 votes
1 answer

Stacked barchart - R programming with ggplot2

Use ggplot2 to map the variables to ...READ MORE

answered Nov 5, 2018 in Data Analytics by Kalgi
• 39,310 points
36 views
0 votes
1 answer

Plotting standard error in R

You can probably use dot plot for ...READ MORE

answered Nov 6, 2018 in Data Analytics by Kalgi
• 39,310 points
24 views
0 votes
1 answer

Error saying "vector size cannot be NA" when using R with data mining

You can use the removesparseterm function.  Removes sparse ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,040 points
350 views
+1 vote
2 answers
0 votes
1 answer

"Error in eval(ei, envir) : object 'RDX2' not found" when trying to source the code in R

This is a very common issue that ...READ MORE

answered Oct 30, 2018 in Data Analytics by Maverick
• 10,040 points
445 views
0 votes
1 answer

Error saying " cannot open the connection" when trying to install a package in R

Try install.packages(“package_name”, repos="http://cran.us.r-p ...READ MORE

answered Nov 26, 2018 in Data Analytics by Maverick
• 10,040 points
263 views