[R] xlims of barplot
Marc Schwartz
MSchwartz at medanalytics.com
Thu Nov 13 23:43:52 CET 2003
On Thu, 2003-11-13 at 15:53, Paul Sorenson wrote:
SNIP
> Sorry for being vague, it is the latter case, vertical bars. The data
> doesn't satisfy condition 1. The family of 6 plots is datestamped data,
> the first plot showing all defects, then each subsequent plot showing
> defects of each severity level we define. The min and max of each of the
> subsequent datasets is in general a subset of the full dataset. I can
> easily plot them but it would be nice to keep the same x limits on each
> graph. The x data is POSIXct although I suspect that is not relevant.
OK...I think I understand what you are doing.
You want a series of barplots that have "space" for the same number of
vertical bars along the x axis, but there may be gaps in the series for
any given barplot. Presumably, those gaps may be anywhere in the time
series along the x axis.
Hint: barplot() will leave gaps in the bar series where an NA appears in
the vector or in a matrix column of height values.
Thus, if you want all of your barplots to have space for say 12 vertical
bars, even though some may only have 7, you can do something like the
following:
# Let's plot these two vertically arranged for show
# First save pars and then set device to two rows
opar <- par(no.readonly = TRUE)
par(mfrow = c(2, 1))
# Example of complete data barplot()
barplot(1:12)
#Example of partial data
MyData <- c(1, 2, NA, 4, NA, NA, NA, 8, 9, 10, 11, NA)
barplot(MyData)
# restore pars
par(opar)
So, the key is to be sure that the vector or matrix has the same number
of elements or matrix columns in each dataset. For your incomplete
datasets, pad each series with NA's to fill out the missing entries in
the time series.
Does that do what you want?
HTH,
Marc Schwartz
More information about the R-help
mailing list