2012-06-05 24 views
2

我剛開始嘗試使用R中的GGPLOT2包可視化我的數據,終於到達了一個點,這裏幾乎一切都看起來不錯失蹤。意,該軸被正確地標記的,有正確的勾號標記等實際的圖形沒有錯誤消息

現在的問題是,雖然我運行下面的代碼時收到任何錯誤消息,小區內的實際曲線圖中沒有顯示出來。這讓我很難弄清楚,出了什麼問題。爲什麼這是(不)發生的任何建議將非常感激。

time <- seq(as.Date("2010-04-01"), as.Date("2012-02-01"), by = "2 months") 

日期,用作蜱標記的矢量。從數據中最早的日期開始的每2個月的標記,直到最後一天之後。

qplot(date, sums/1000, data=sums[(sums$lake=="Gollinsee") & (sums$maize=="no maize"),] ,color=location, group=location, main="Gollinsee without maize") + 
    geom_line(size=0.7) + geom_point(size=3) + 
    labs(x="Date", y=expression("Total C [" * g %.% m^-3 * "]")) + 
    scale_x_date(breaks=(time), limits=c(min(time), max(time)), labels=format.Date(time, "%b %Y")) 

一切都按預期運行,直到我添加最後一行。沒有它,x軸太雜亂,日期格式不合要求。那麼有了它,會產生下面的圖像(可惜我不能發表圖片呢,鏈接應該工作,雖然):

http://i.stack.imgur.com/I6rRY.png

不是很像樣的方式情節貌似沒有修改的X-軸。

http://i.stack.imgur.com/WidpZ.png

親切的問候!

編輯: dput的輸出(總和)

structure(list(date = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 
5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 11L, 11L, 19L, 10L, 10L, 
12L, 12L, 14L, 14L, 16L, 16L, 19L, 15L, 20L, 20L, 13L, 13L, 17L, 
17L, 18L, 20L, 20L, 22L, 22L, 18L, 4L, 21L, 25L, 28L, 25L, 25L, 
23L, 23L, 23L, 23L, 28L, 24L, 24L, 24L, 24L, 22L, 22L, 22L, 22L, 
21L, 25L, 35L, 35L, 37L, 37L, 35L, 35L, 37L, 37L, 39L, 39L, 39L, 
39L, 36L, 28L, 33L, 33L, 33L, 33L, 31L, 31L, 31L, 31L, 29L, 29L, 
29L, 26L, 26L, 26L, 26L, 27L, 27L, 27L, 27L, 30L, 30L, 30L, 30L, 
32L, 32L, 32L, 32L, 34L, 34L, 34L, 34L, 38L, 38L, 38L, 38L, 36L, 
36L), .Label = c("2010-04-06", "2010-04-08", "2010-05-04", "2010-05-06", 
"2010-05-19", "2010-06-01", "2010-06-03", "2010-06-29", "2010-06-30", 
"2010-07-27", "2010-07-29", "2010-08-24", "2010-08-26", "2010-09-21", 
"2010-09-23", "2010-10-19", "2010-10-21", "2010-11-16", "2010-11-18", 
"2011-01-05", "2011-02-24", "2011-03-22", "2011-04-05", "2011-04-07", 
"2011-05-03", "2011-05-05", "2011-05-31", "2011-06-01", "2011-06-28", 
"2011-07-01", "2011-07-26", "2011-07-28", "2011-08-23", "2011-08-25", 
"2011-09-20", "2011-09-22", "2011-10-17", "2011-10-20", "2012-01-10" 
), class = "factor"), lake = structure(c(1L, 1L, 2L, 2L, 1L, 
1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Gollinsee", 
"Schulzensee"), class = "factor"), location = structure(c(2L, 
1L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 
1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 
1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 
2L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 
1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L 
), .Label = c("littoral", "pelagic"), class = "factor"), maize = structure(c(2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 
2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 
1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 
2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 
2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 
2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L 
), .Label = c("maize", "no maize"), class = "factor"), sums = c(388.7, 
254.5, 320.4, 373.3, 224.1, 182.4, 245.5, 258.7, 47.7, 60.5, 
58.3, 103.7, 311.9, 207.7, 283.9, 308.3, 237.9, 165.4, 556.4, 
1090.4, 1792.6, 1350.5, 932.4, 526.5, 1157.8, 2343.7, 4570.9, 
393.2, 315.5, 351, 1008, 504.8, 289.9, 113.4, 117.7, 707.9, 193.4, 
122.2, 828.2, 1106.4, 837.8, 148, 777.6, 1824.6, 388, 1658.6, 
636.3, 1434.7, 770.8, 1776.4, 705.9, 1634.5, 1237.1, 1882.5, 
1073.8, 2283, 1030.7, 273, 194.6, 788.6, 1034.9, 420.7, 404.6, 
295.9, 332, 229.3, 381, 304.2, 780.2, 227.3, 50.6, 509.3, 209.7, 
675.8, 691.9, 651.7, 635.1, 560.8, 602.2, 1243.1, 733.8, 669.1, 
574.5, 379.6, 1405.3, 513.6, 612.4, 1396.4, 256.7, 486.8, 521.3, 
55.5, 48.2, 181.7, 281.3, 322.7, 478.1, 208.4, 173.8, 599.2, 
262.9, 760.7, 365.5, 746.6, 790.3, 581.7, 388.9, 826.4, 132.6, 
167.5, 817.6, 425.1, 582.2)), .Names = c("date", "lake", "location", 
"maize", "sums"), class = "data.frame", row.names = c(NA, -113L)) 

親切的問候!

+1

你可以發佈一部分data.frame'sums'。沒有它,我們只會猜測。使用'dput(sums)'或者它的一部分太大了。 – Justin

回答

4

的問題是,「日期」,在資金,目前的一個因素。將其轉換爲日期類型。你可能不需要搞定「時代」,因爲我認爲你只是這樣做,所以軸看起來不那麼混亂。將日期作爲實際日期類型應該稍微清理標籤。

sums$date <- as.Date(sums$date) 

qplot(date, 
     sums/1000, 
     data=sums[(sums$lake=="Gollinsee") & (sums$maize=="no maize"),], 
     color=location, 
     group=location, 
     main="Gollinsee without maize") + 
geom_line(size=0.7) + 
geom_point(size=3) + 
labs(x="Date", y=expression("Total C [" * g %.% m^-3 * "]")) 
+0

這完全做到了!非常感謝你! – redwyn

相關問題