[R] ploting missing data

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Fri Sep 7 16:43:10 CEST 2007


Markus Schmidberger wrote:
> Hello,
>
> I have this kind of dataframe and have to plot it.
>
> data <- data.frame(sw= c(1,2,3,4,5,6,7,8,9,10,11,12,15),
>     zehn =         
> c(33.44,20.67,18.20,18.19,17.89,19.65,20.05,19.87,20.55,22.53,NA,NA,NA),
>      zwanzig =     
> c(61.42,NA,26.60,23.28,NA,24.90,24.47,24.53,26.41,28.26,NA,29.80,35.49),
>      fuenfzig =    
> c(162.51,66.08,49.55,43.40,NA,37.77,35.53,36.46,37.25,37.66,NA,42.29,47.80) 
> )
>
> The plot should have lines:
> lines(fuenfzig~sw, data=data)
> lines(zwanzig~sw, data=data)
>
> But now I have holes in my lines for the missing values (NA). How to 
> plot the lines without the holes?
> The missing values should be interpolated or the left and right point 
> directly connected. The function approx interpolates the whole dataset. 
> Thats not my goal!
> Is there no plotting function to do this directly?
>
>   
Just get rid of the NAs:

lines(fuenfzig~sw, data=data, subset=!is.na(fuenfzig))

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list