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
• 11,360 points
1,665 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 7, 2018 by Maverick
• 10,840 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,660 points
1,426 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,250 points
3,824 views
0 votes
1 answer
+1 vote
2 answers

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
82,285 views
+10 votes
3 answers

Which is a better initiative to learn data science: Python or R?

Well it truly depends on your requirement, If ...READ MORE

answered Aug 9, 2018 in Data Analytics by Abhi
• 3,720 points
1,625 views
+1 vote
2 answers

Stacked barchart - R programming with ggplot2

Use position = stack inside geom_bar() ggplot(mydata, aes(x = ...READ MORE

answered Aug 23, 2019 in Data Analytics by anonymous
• 33,030 points
928 views
+1 vote
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
• 52,350 points
677 views
+1 vote
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,840 points
4,829 views
+1 vote
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,840 points
5,108 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://cr ...READ MORE

answered Nov 26, 2018 in Data Analytics by Maverick
• 10,840 points
9,153 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP