0

I have a data frame in R called pros.dat, which has 97 obs of 9 variables. I am trying to use lapply() to plot 8 of those variables against one in particular, SVI. This is the code I am using:

plots = lapply(pros.dat[,-5], FUN = plot, x = pros.dat$svi)

When I run the code, the x-axis correctly plots SVI, but the y-axis plots x[[i]] (see image). Does anyone know how I can fix the code to get each variable (excluding SVI) on the y-axis? Thanks.

current output

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Feb 18 '22 at 03:40
  • Loop over the column names instead: `lapply(names(pros.dat)[-5], FUN = function(yvar) plot(x = pros.dat$svi, y=pros.dat[[yvar]], ylab=yvar))` – MrFlick Feb 18 '22 at 03:44

0 Answers0