[R] 'matplot' for matrix with NAs: broken lines

Gabor Grothendieck ggrothendieck at gmail.com
Wed May 5 21:45:44 CEST 2010


Try this:

library(zoo)
matplot(na.approx(b), type = "l")

On Wed, May 5, 2010 at 2:30 PM, Tao Shi <shitao at hotmail.com> wrote:
>
> Hi list,
>
> I know that points involving NAs are not plotted in 'matplot', but when I plot them as lines, I still want the lines to connect all the points (i.e. not broken where there are NAs).  Please see the example below.  How can I achieve this in 'matplot'?  If I can't, any good alternatives so I don't have to use 'plot' + 'lines' and loop through all the columns.
>
> Many thanks!
>
> ...Tao
>
>> set.seed(1234)
>> a=b=matrix(rnorm(9), 3,3)
>> b[2,2]=NA
>> matplot(a, type="b")
>> matplot(b, type="b")  ## I want the two "2" connected!
>> matplot(b, type="l")  ## Now my data for the second column are missing from the graph
>
>
> _________________________________________________________________
> Hotmail is redefining busy with tools for the New Busy. Get more from your inbox.
>
> N:WL:en-US:WM_HMP:042010_2
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list