2013-03-09 227 views
1

我有一個所謂的「降雨」的數據集,前幾行支線劇情,劇情無厘頭

Year Month  Date cuftsec   lsec log10lsec 
1 1997 January 1/15/1997 57.100 3.360907e-02 -1.473544 
2 1997 February 2/15/1997 13.800 8.122686e-03 -2.090300 
3 1997 March 3/15/1997 5.100 3.001866e-03 -2.522609 
4 1997 April 4/15/1997 2.210 1.300812e-03 -2.885786 
5 1997  May 5/15/1997 0.469 2.760590e-04 -3.558998 
6 1997  June 6/15/1997 0.000 5.886000e-09 -8.230180 

我想獲得日期和log10lsec的線圖。當我嘗試

with(rainfall, plot(x = Date, y = log10lsec, type = "l")) 

我得到一個積分的點(好像type =「l」不在那裏)。

如果我設置了另一個圖然後添加一行,例如與

with(rainfall, plot(x = Date, y = log10lsec)) 
with(rainfall, lines(x = Date, y = log10lsec)) 

我得到一個荒謬的線圖,以看似隨機的順序連接點。

dput(頭(降雨))產量:

structure(list(Year = c(1997L, 1997L, 1997L, 1997L, 1997L, 1997L 
), Month = structure(c(5L, 4L, 8L, 1L, 9L, 7L), .Label = c("April", 
"August", "December", "February", "January", "July", "June", 
"March", "May", "November", "October", "September"), class = "factor"), 
    Date = structure(c(1L, 49L, 61L, 73L, 85L, 97L), .Label = c("1/15/1997", 
    "1/15/1998", "1/15/1999", "1/15/2000", "1/15/2001", "1/15/2002", 
    "1/15/2003", "1/15/2004", "1/15/2005", "1/15/2006", "1/15/2007", 
    "1/15/2008", "10/15/1997", "10/15/1998", "10/15/1999", "10/15/2000", 
    "10/15/2001", "10/15/2002", "10/15/2003", "10/15/2004", "10/15/2005", 
    "10/15/2006", "10/15/2007", "10/15/2008", "11/15/1997", "11/15/1998", 
    "11/15/1999", "11/15/2000", "11/15/2001", "11/15/2002", "11/15/2003", 
    "11/15/2004", "11/15/2005", "11/15/2006", "11/15/2007", "11/15/2008", 
    "12/15/1997", "12/15/1998", "12/15/1999", "12/15/2000", "12/15/2001", 
    "12/15/2002", "12/15/2003", "12/15/2004", "12/15/2005", "12/15/2006", 
    "12/15/2007", "12/15/2008", "2/15/1997", "2/15/1998", "2/15/1999", 
    "2/15/2000", "2/15/2001", "2/15/2002", "2/15/2003", "2/15/2004", 
    "2/15/2005", "2/15/2006", "2/15/2007", "2/15/2008", "3/15/1997", 
    "3/15/1998", "3/15/1999", "3/15/2000", "3/15/2001", "3/15/2002", 
    "3/15/2003", "3/15/2004", "3/15/2005", "3/15/2006", "3/15/2007", 
    "3/15/2008", "4/15/1997", "4/15/1998", "4/15/1999", "4/15/2000", 
    "4/15/2001", "4/15/2002", "4/15/2003", "4/15/2004", "4/15/2005", 
    "4/15/2006", "4/15/2007", "4/15/2008", "5/15/1997", "5/15/1998", 
    "5/15/1999", "5/15/2000", "5/15/2001", "5/15/2002", "5/15/2003", 
    "5/15/2004", "5/15/2005", "5/15/2006", "5/15/2007", "5/15/2008", 
    "6/15/1997", "6/15/1998", "6/15/1999", "6/15/2000", "6/15/2001", 
    "6/15/2002", "6/15/2003", "6/15/2004", "6/15/2005", "6/15/2006", 
    "6/15/2007", "6/15/2008", "7/15/1997", "7/15/1998", "7/15/1999", 
    "7/15/2000", "7/15/2001", "7/15/2002", "7/15/2003", "7/15/2004", 
    "7/15/2005", "7/15/2006", "7/15/2007", "7/15/2008", "8/15/1997", 
    "8/15/1998", "8/15/1999", "8/15/2000", "8/15/2001", "8/15/2002", 
    "8/15/2003", "8/15/2004", "8/15/2005", "8/15/2006", "8/15/2007", 
    "8/15/2008", "9/15/1997", "9/15/1998", "9/15/1999", "9/15/2000", 
    "9/15/2001", "9/15/2002", "9/15/2003", "9/15/2004", "9/15/2005", 
    "9/15/2006", "9/15/2007", "9/15/2008"), class = "factor"), 
    cuftsec = c(57.1, 13.8, 5.1, 2.21, 0.469, 0), lsec = c(0.033609066, 
    0.008122686, 0.003001866, 0.001300812, 0.000276059, 5.886e-09 
    ), log10lsec = c(-1.473543558, -2.090300341, -2.522608715, 
    -2.885785503, -3.55899764, -8.230179742)), .Names = c("Year", 
"Month", "Date", "cuftsec", "lsec", "log10lsec"), row.names = c(NA, 
6L), class = "data.frame") 

TIA

+2

什麼是類'Date'的?這是一個因素嗎? – 2013-03-09 21:44:28

+2

請讓你的例子可重現。我們不知道「設置另一個圖」的含義。 – 2013-03-09 21:44:56

+1

您可以通過發佈'dput(降雨)'的輸出來使您的示例具有可再現性。 – 2013-03-09 21:51:03

回答

3

我覺得這個問題正是Date是一個因素。這似乎工作:

with(dat,plot(as.Date(Date,format="%m/%d/%Y"),log10lsec,type="l")) 

,或者如果你想轉換永久日期,

dat <- transform(dat,Date=as.Date(Date,format="%m/%d/%Y")) 
with(dat,plot(log10lsec~Date,type="l")) 
+0

謝謝!這工作。 – 2013-03-09 22:08:32