0

I have 2 data sets that I would like to plot. I would be using the xlim (200-820) and the same ylim (0-100) but the x values of these two data sets don't exactly match up, so I can't run a matrix or data.frame. I just basically want to plot the multiple data sets on one sheet that has fixed axes.

I've looked into ggplot and dataframe creation but because I have differing x axis values for every set I didn't think it was quite the right solution, however I may have interpreted their use incorrectly

plot(x1, y1, xlim=c(200,820), type = "l", xlab="Wavelength", ylab="Reflectance")
plot(x2, y2, xlim=c(200,820), type = "l", xlab="Wavelength", ylab="Reflectance")
axis(1,at=seq(200,850,50))

When done correctly, the plot should look like a bunch of graphs over one another with the same axes.

1 Answers1

0

Welcome to SO.

It is a bit unclear what you mean by 'sheet'. If you are refering to the same plot window, using base R you could use either points or lines

plot(x1, y1, xlim=c(200,820), type = "l", xlab="Wavelength", ylab="Reflectance")
lines(x2, y2)
axis(1,at=seq(200,850,50))

If you are looking for multiple 'plots' you can split the plot window using par(mfrow = c(ncol, nrow)). For example plotting side by side:

par(mfrow = c(1,2))
plot(x1, y1, xlim=c(200,820), type = "l", xlab="Wavelength", ylab="Reflectance")
axis(1,at=seq(200,850,50))
plot(x2, y2, xlim=c(200,820), type = "l", xlab="Wavelength", ylab="Reflectance")
axis(1,at=seq(200,850,50))
Oliver
  • 6,460
  • 2
  • 8
  • 33
  • THANK YOU! I knew there had to be an easy solution that I was just missing. The lines function was exactly what I was looking for. – Colman Betler Apr 26 '19 at 04:09
  • No problem, i am glad i could've helped. As you are new to SO, i suggest setting the answer as 'answered'. Gives me a few points and lets other users know that the question is resolved. :-) – Oliver Apr 26 '19 at 04:10