Search code examples
rplotaxis-labelsaxes

How to draw the same Y-axis no matter what data is being plotted in R?


I have two multiple line graphs drawn in R using matplot().

The graphs are from the same time series data but showing two differing clusters. I want to draw the y-axis so that it is identical in each plot I draw regardless of the data (range, max, min etc) that is used.

Could anybody suggest a means to achieve this in R?

Thanks!


Solution

  • Setting the ylim parameter should achieve what you are trying to do

    plot_max <- 200
    plot_min <- 0
    plot1 <- matplot(data_set1, ylim = c(plot_min, plot_max)
    plot2 <- matplot(data_set2, ylim = c(plot_min, plot_max)
    

    This should get you what you want.