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