Skip to content

not plotting when non-existent

3 messages · Luis Ridao Cruz, Sundar Dorai-Raj, Achim Zeileis

#
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
_              
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 Ridao Cruz wrote on 4/12/2005 10:08 AM:
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
#
On Tue, 12 Apr 2005 16:08:54 +0100 Luis Ridao Cruz wrote:

            
I would store the data as a "ts" object with NAs in it. If x is the
"data.frame" above, you could do

## create regular time scale
y <- data.frame(year = 1986:2004)
## merge data
lgd <- merge(x, y, by = "year", all = TRUE)[,2]
## create ts object
lgd <- ts(lgd, start = 1986)
## plot
plot(lgd, type = "o", pch = 16)

hth,
Z