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

Tao Shi shitao at hotmail.com
Wed May 5 22:11:26 CEST 2010


Thanks, Gabor!  So, there is no way I can change some graphic parameters in 'matplot' to get this?

    
I forgot to mention that I purposely use type="b", so I know where the missing data are.  With imputed data, either using "b" or "l", there is no way to keep track of NAs.  Plus, in my real data sometimes there is only one non-missing value in a particular column and na.approx can't work (well I could selectively impute the NAs ... )

So far, my best solution to this is to use "xyplot".  It does this by default, but of course I need some data manipulation first.


..Tao



----------------------------------------
> From: ggrothendieck at gmail.com
> Date: Wed, 5 May 2010 15:45:44 -0400
> Subject: Re: [R] 'matplot' for matrix with NAs: broken lines
> To: shitao at hotmail.com
> CC: r-help at r-project.org
>
> Try this:
>
> library(zoo)
> matplot(na.approx(b), type = "l")
>
> On Wed, May 5, 2010 at 2:30 PM, Tao Shi  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")
[[elided Hotmail spam]]
>>> 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.
>>
 		 	   		  
_________________________________________________________________
Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox.

N:WL:en-US:WM_HMP:042010_1
______________________________________________
R-help at r-project.org mailing list

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