0

I am trying to make a scatterplot of two columns (V13 and V21) shown in the sample dataset below. I want the row number on the x axis and each column on the y axis - on the same figure. So each column has its own set of y values. When I go to plot this, however, I get this:

Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' and 'y' lengths differ

The dataframe I'm working with is called "Vs.highvar". The data has 1000 obs of 2 variables, and I want the x axis to be the number of rows (1000), so I guess that's the problem. How do I do this? Do I have to split the data into two separate columns/two separate dataframes? I'm very new to R. I've tried split(), separate(), plot(), ggplot2.scatterplot(), scatterplot().

Code so far:

Vs <- read.csv(file="x.csv", 
               header=TRUE,
               fill=TRUE)

#find variables with largest variance 
head(Vs)
variances <- apply(X=Vs, MARGIN=2, FUN=var)
sortedvars <- sort(variances, 
                   decreasing=TRUE, 
                   index.return=TRUE)$ix[1:2]

Vs.highvar <- Vs[, sortedvars]
Vs.highvar #returns variables V13 and V21

#create scatterplot
plot(nrow(Vs.highvar), Vs.highvar$V13, 
     main="Variances")

For reference: sample of dataset environment

Jay
  • 3
  • 2
  • Please [make this question reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by including code and the data in a plain text format (using _e.g._ `dput(head(Vs.highvar))`). Other users cannot copy/paste data from images. – neilfws Nov 02 '20 at 00:36
  • [Please do not provide code/data as images.](https://idownvotedbecau.se/imageofcode) Upload the file instead and provide the link to your file. – Mr. T Nov 05 '20 at 16:43

0 Answers0