I'm trying to graph the data below using ggplot2
.
ggplot(dailyHDD, aes(x=Date, y=cumHDD, colour=WinterID, group=WinterID)) +
geom_line(linetype="dashed", size=1) +
scale_x_date(labels=date_format("%B"), breaks=date_breaks("month"))
Data structure:
structure(list(SiteID = structure(c(1L, 1L, 1L, 1L, 1L), .Label = "NW_SB", class = "factor"),
SubstrateID = structure(c(1L, 1L, 1L, 1L, 1L), .Label = "B", class = "factor"),
WinterID = structure(c(1L, 1L, 1L, 1L, 1L), .Label = c("2002_2003",
"2003_2004", "2004_2005", "2005_2006", "2006_2007", "2007_2008"
), class = "factor"), Date = structure(c(11992, 11993, 11994,
11995, 11996), class = "Date"), HeatingDegreeDay = c(0, 0,
0, 0, 0), cumHDD = c(0, 0, 0, 0, 0), Month = structure(c(1L,
1L, 1L, 1L, 1L), .Label = c("11", "12", "01", "02", "03"), class = c("ordered",
"factor"))), .Names = c("SiteID", "SubstrateID", "WinterID",
"Date", "HeatingDegreeDay", "cumHDD", "Month"), row.names = c(NA,
5L), class = "data.frame")
My data:
SiteID SubstrateID WinterID Date HeatingDegreeDay cumHDD Month
15 NW_SB B 2002_2003 2002-11-15 0.0000000 0.0000000 11
16 NW_SB B 2002_2003 2002-11-16 0.0000000 0.0000000 11
17 NW_SB B 2002_2003 2002-11-17 0.0000000 0.0000000 11
18 NW_SB B 2002_2003 2002-11-18 0.0000000 0.0000000 11
19 NW_SB B 2002_2003 2002-11-19 0.3724242 0.3724242 11
20 NW_SB B 2002_2003 2002-11-20 0.0000000 0.3724242 11
21 NW_SB B 2002_2003 2002-11-21 0.0000000 0.3724242 11
22 NW_SB B 2002_2003 2002-11-22 0.0000000 0.3724242 11
23 NW_SB B 2002_2003 2002-11-23 0.2773077 0.6497319 11
24 NW_SB B 2002_2003 2002-11-24 0.2679310 0.9176630 11
25 NW_SB B 2002_2003 2002-11-25 0.0000000 0.9176630 11
26 NW_SB B 2002_2003 2002-11-26 0.0000000 0.9176630 11
27 NW_SB B 2002_2003 2002-11-27 0.0000000 0.9176630 11
28 NW_SB B 2002_2003 2002-11-28 0.0000000 0.9176630 11
29 NW_SB B 2002_2003 2002-11-29 0.2063889 1.1240519 11
30 NW_SB B 2002_2003 2002-11-30 1.1830556 2.3071074 11
31 NW_SB B 2002_2003 2002-12-01 0.1811111 2.4882185 12
32 NW_SB B 2002_2003 2002-12-02 1.0348276 3.5230461 12
33 NW_SB B 2002_2003 2002-12-03 1.0064286 4.5294747 12
34 NW_SB B 2002_2003 2002-12-04 0.6238462 5.1533208 12
35 NW_SB B 2002_2003 2002-12-05 0.1628571 5.3161780 12
36 NW_SB B 2002_2003 2002-12-06 0.0000000 5.3161780 12
37 NW_SB B 2002_2003 2002-12-07 0.8393103 6.1554883 12
38 NW_SB B 2002_2003 2002-12-08 0.1448000 6.3002883 12
39 NW_SB B 2002_2003 2002-12-09 0.0000000 6.3002883 12
40 NW_SB B 2002_2003 2002-12-10 1.0744444 7.3747328 12
41 NW_SB B 2002_2003 2002-12-11 0.0000000 7.3747328 12
42 NW_SB B 2002_2003 2002-12-12 0.2100000 7.5847328 12
43 NW_SB B 2002_2003 2002-12-13 1.5238889 9.1086217 12
44 NW_SB B 2002_2003 2002-12-14 2.2277778 11.3363994 12
45 NW_SB B 2002_2003 2002-12-15 4.1022222 15.4386217 12
46 NW_SB B 2002_2003 2002-12-16 4.5455556 19.9841772 12
47 NW_SB B 2002_2003 2002-12-17 4.3391667 24.3233439 12
48 NW_SB B 2002_2003 2002-12-18 3.3436111 27.6669550 12
49 NW_SB B 2002_2003 2002-12-19 1.9597222 29.6266772 12
50 NW_SB B 2002_2003 2002-12-20 0.5586111 30.1852883 12
...
150 NW_SB B 2002_2003 2003-03-30 0.00000000 150.0560881 03
151 NW_SB B 2002_2003 2003-03-31 0.00000000 150.0560881 03
152 NW_SB B 2003_2004 2003-11-15 0.00000000 0.0000000 11
ggplot
plots chronologically and I end up with a line for 2002-2003 that raises vertically to value 150, and the same for each consecutive year. Instead I want the plot to show a line that rises diagonally for each year, starting at 0 on the y-axis, and November on the x-axis, and rises over time (Date) to its end cumHDD value.
I'm new to R and to SO. Thank you @Roman Luštrik for posting my plot. Thanks for your help.
Month
and notDate
. – Señor O