1
votes

I have a data.frame with the following characteristics:

+-----------------------------------------+
|         earning   budget    ts    total |
+-----------------------------------------+
| 1            14      3 2012-01-18    11 |
| 2            15      3 2012-01-19    23 |
| 3            22      4 2012-01-20    42 |
| 4            43      4 2012-01-21    82 |
| 5            19      5 2012-01-22    98 |
| 6            24      5 2012-01-23   119 |
+-----------------------------------------+

And I am using the following code to get a ggplot

qplot(ts, total, data=res, geom="histogram")

But when I run the following code I get a graph without line?

qplot(ts, total, data=res, geom="line")

I tried

plot(res)
and that works fine.

Any idea why the "line" graph is not understanding my plot?

2

2 Answers

3
votes

What data type is ts? (What does str(YourDataFame$ts) give?) If it is character or factor, then you need to add a group=1 to the aes() when you make a line since otherwise it only draws lines per group, and each character/factor defines a different group (and thus each x value is a separate group).

0
votes

Not sure what wwhen is exactly, but if I assume its your ts column in the table you provided, your qplot(... histogram) shouldn't work without adding stat='identity'.

happy to help... just confused!

for others:

> dput(res)
structure(list(earning = c(14, 15, 22, 43, 19, 24), budget = c(3, 
3, 4, 4, 5, 5), ts = structure(c(15357, 15358, 15359, 15360, 
15361, 15362), class = "Date"), total = c(11, 23, 42, 82, 98, 
119)), .Names = c("earning", "budget", "ts", "total"), row.names = c(NA, 
-6L), class = "data.frame")