Reputation: 53
I have an automatically generated plot as below. I would like to force the y-axis of the BaseR plot to always start from 0. I can't use ylim because I don't know what the upper value is, as it changes depending on the output of the model run.
Sample output dataset:
dput(output)
structure(c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 50, 69.3156953492534, 69.318942246502,
69.3221842690373, 69.3254213876886, 69.328653593418, 69.3318808298525,
69.3351031300752, 69.3383203643342, 69.3415326399219, 69.3447398445571,
69.347942054021, 69.3511390646152, 69.3543309965411, 69.3575177870547,
69.3606994090412, 69.3638758413145, 69.3670470505769, 69.3702130227672,
69.3733737166025, 69.3765291188801, 5000, 18862.7067825912, 32701.2878238389,
46515.4231109193, 60305.1557762178, 74070.5350235935, 87811.6110650452,
101528.431040477, 115221.04114851, 128889.487348218, 142533.821290191,
156154.07212382, 169750.309580026, 183322.569810166, 196870.894746817,
210395.328060903, 223895.908282952, 237372.694773718, 250825.703835891,
264254.993125685, 277660.610657547, 2, 2.13669838484446, 2.1371918659313,
2.13768517063436, 2.13817826875458, 2.1386711454299, 2.13916374738259,
2.13965609413379, 2.14014807364301, 2.14063976569378, 2.14113107150291,
2.14162204800553, 2.14211251951205, 2.14260257795796, 2.14309216606161,
2.14358125521914, 2.14406982238996, 2.14455783154718, 2.14504526882503,
2.1455320920089, 2.14601828305136, 200, 200.222037812752, 200.45059302352,
200.679119601703, 200.907601138121, 201.136029483869, 201.364375754764,
201.59265036992, 201.820792720557, 202.04884578298, 202.276756080509,
202.504554314939, 202.732145381519, 202.959578907475, 203.18682382934,
203.413864602637, 203.640688692808, 203.867276503349, 204.09362050977,
204.319697782116, 204.545498454914), .Dim = c(21L, 5L), .Dimnames = list(
NULL, c("time", "w", "x", "y", "z")), istate = c(2L, 111L,
231L, NA, 3L, 3L, 0L, 84L, 24L, NA, NA, NA, NA, 9L, 2L, 2L, NA,
NA, NA, NA, NA), rstate = c(1, 1, 20.9107964764918, 0, 0.00162452941396683
), lengthvar = 4L, class = c("deSolve", "matrix"), type = "lsoda")
Currently, running plot(output)
with this deSolve object after using par(oma = c(0, 0, 3, 0))
creates four plots of the four variables on the same screen. However, it automatically chooses ylim values. I would like all four of these plots to start from 0.
Upvotes: 0
Views: 869
Reputation: 1089
You can pass a ylim
input to set the limits of the axis. If you don't know the upper limit use max(y)
.
x <- 1:1000
y <- 500 + 100*sin(x/10)
plot(x,y, 'l', ylim = c(0,max(y)))
Upvotes: 2