1

My code looks like this so far:

library(tidyverse)

load(Transport_Survey)

View(Transport_Survey)

variables <- names(Transport_Survey)

for (x in variables) {
  for (y in variables) {
    plot(x,y)
  }
}

Unfortunately I'm getting errors about introducing 'NaS' via coercision and things like 'In min(x) : no non-missing arguments to min; returning Inf'

What can I do to remedy this?

Piomicron
  • 113
  • 4
  • 1
    Try `plot(Transport_Survey[[x]], Transport_Survey[[y]])` – akrun Nov 18 '19 at 21:33
  • 1
    To help you with search terms, if you're trying to lay all the scatterplots out together that's often called a scatterplot matrix – camille Nov 18 '19 at 21:34
  • Does this answer your question? [r: Plotting each column against each column](https://stackoverflow.com/questions/36582772/r-plotting-each-column-against-each-column) – camille Nov 18 '19 at 21:41

1 Answers1

2

Regarding the errors in the OP's code, x and y refers to each of the column names and it is a string. We need to extract the column from the dataset

for (x in variables) {
 for (y in variables) {
    plot(Transport_Survey[[x]], Transport_Survey[[y]])
 }
}

For scatter plot, an option is pairs

pairs(mtcars)
akrun
  • 874,273
  • 37
  • 540
  • 662
  • 1
    Hi, that's really helpful, thank you. Is there a way of showing the original variable name on the axes? – Piomicron Nov 19 '19 at 17:57