Reputation: 13
I have my data set up to run a dataframe of about 85 columns of species through a for loop to produce one plot per species (samples as rows). Some of them contain only 0 values which plot dots across the middle of the plot (y range (-1, 1)) and I want them at the bottom (y range (0, + value)). The species that do not contain all zeros are scaled to the ymax so I don't want to set the same max for all species as the y variable is quite... variable. Is there a way for me to set a ymin without setting a ymax so that 0 values are always at the bottom of a plot? Thank you in advance!
Upvotes: 0
Views: 4483
Reputation: 25864
Take a punt: You cant set one side of ylim
(as far as i know), but as the default limits of ylim
are defined as the maximum and minimum of the data, you can just reproduce this behaviour.
# Some example data - its always good to include this in your question
dat <- data.frame(spec1 = 1:10, spec2 = 11:20, spec3 = 0, spec4 = 1:10)
# set plot window
par(mfrow=c(2,2))
# default plot - with no ylim scaling
for(i in names(dat)) { plot(dat[[i]]) }
which gives
Add the ylim
. The maximum is taken as the maximum of the data or 1
(or whatever value you want to specify)
for(i in names(dat)) {
plot(dat[[i]], ylim=c(min(dat[[i]]), max(dat[[i]],1)))
}
Which produces
Notice the limits in the other plots are unchanged
Upvotes: 1