[R] not plotting when non-existent

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Tue Apr 12 17:14:28 CEST 2005



Luis Ridao Cruz wrote on 4/12/2005 10:08 AM:
> R-help,
> 
> I'm trying to plot the following:
> 
>      year      lgd
> 1  1986 136.97479
> 2  1987  69.10377
> 3  1988  67.66744
> 4  1989  71.60316
> 5  1990  62.06897
> 6  1992   6.25000
> 7  1993  27.72021
> 8  1995  23.83648
> 9  1996  10.29412
> 10 1997  95.67487
> 11 1998  82.09367
> 12 1999  56.60401
> 13 2000  29.80864
> 14 2001  23.77535
> 15 2002  48.30378
> 16 2003  83.47571
> 17 2004  74.58711
> 
> There are 2 missing years 1991 and 1994.
> Is it possible to plot this simple data set so that there is not "line"
> connection between
> 1990-1992 and 1993-1995?
> 
> I currently use 'plot(...., type = "o", pch = 16)' 
> 
> I could as well plot 'pieces' of the vectors with "lines" but I was
> wondering wether there is a simple function to achieve this.
> 
> I run on Windows XP
> 
> 
>>version
> 
>          _              
> platform i386-pc-mingw32
> arch     i386           
> os       mingw32        
> system   i386, mingw32  
> status                  
> major    2              
> minor    0.1            
> year     2004           
> month    11             
> day      15             
> language R  
> 
> Thank you in advance
> 


Luis,

Place an NA for 1991 and 1994.

missingData <- data.frame(year = c(1991, 1994), lgd = rep(NA, 2))
newData <- rbind(oldData, missingData)
newData <- newData[order(newData$year), ]
plot(lgd ~ year, newData, type = "o")

HTH,

--sundar




More information about the R-help mailing list