[R] Time Series-like barplot?

Spencer Graves spencer.graves at pdf.com
Wed Mar 19 20:56:59 CET 2003


The following produces thick lines like you requested:

	plot(c(1, 10), c(1, 5), type="n")
	for(j in 1:5)
	  lines(range(which(!is.na(foo.mat[,j]))), rep(j, 2), lwd=10)

If you want open bars, then draw boxes inside the loop.

Is this satisfactory?
Spencer Graves

Andy Bunn wrote:
> I have data structured like the following:
> 
> 
>>foo.mat <- matrix(NA, ncol = 5, nrow = 10)
>>foo.mat[2:6,1] <- 1
>>foo.mat[1:3,2] <- 1
>>foo.mat[3:10,3] <- 1
>>foo.mat[1:10,4] <- 1
>>foo.mat[8:10,5] <- 1
>>foo.mat
> 
>       [,1] [,2] [,3] [,4] [,5]
>  [1,]   NA    1   NA    1   NA
>  [2,]    1    1   NA    1   NA
>  [3,]    1    1    1    1   NA
>  [4,]    1   NA    1    1   NA
>  [5,]    1   NA    1    1   NA
>  [6,]    1   NA    1    1   NA
>  [7,]   NA   NA    1    1   NA
>  [8,]   NA   NA    1    1    1
>  [9,]   NA   NA    1    1    1
> [10,]   NA   NA    1    1    1
> 
> I am trying to create a plot with horizontal bars that has 1:10 on the
> x-axis and plots the length of the data (i.e., 1) in the correct context.
> E.g.,:
> 
>   5               ------
>   4 --------------------
>   3     ----------------
>   2 -----
>   1   ---------
>    1-2-3-4-5-6-7-8-9-10
> 
> 
> Does any body have a suggestion?
> 
> Thanks, Andy
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help



More information about the R-help mailing list