tags:

views:

51

answers:

2

This is a follow on from my last question relating to plotting timestamps in R. I am using the same XML file. The question has been answered and is working except for the following command:

qplot(timeStamp,Price,data=test.df,geom=c("point","line"),color="Measured", shape="Measured",linetype="Measured", scale_y_continuous(limits = c(10,26)))

The problem is that the line is not shown on the graph, but the points are. I have searched online but there does not seem to be a solution. Is there other options / additional commands I need to get the line to display?

Sorry if this seems such a simple question but I am a total beginner and have found the people on this site to be extremely helpful and this has been very much appreciated.

+1  A: 

When the x-axis is a factor, you need to define the groups across which you want to draw the line. That is, if you want to draw a line for every unique group defined by A, you would pass group = A to qplot(). If the lines are going to be defined by a combination of A and B, you would pass group = A:B.

With this data, since there aren't any groups, defined in the data frame, pass group = 1 to qplot(). That should do the trick.

JoFrhwld
Thanks JoFrhwld. This seems to be an odd solution.
Anthony Keane
This is not a good idea as it conceals the fact that the x-axis is no longer linear - it's a factor.
hadley
@hadley you're right. I don't think it's always bad in all cases to draw a line across a factor, like when the factor has a well defined order, but not magnitude. For this case though, converting to the right time format would be best.
JoFrhwld
It's definitely useful - but you should be doing it deliberately, not because your data is the wrong format.
hadley
+2  A: 

Your problem is probably that you haven't converted timeStamp to a time stamp - it's probably currently stored as a factor. Without seeing your data I can't tell you exactly what you need to do to fix it, but it's likely to involve strptime.

hadley
Yep, which I already told Anthony here: http://stackoverflow.com/questions/3226821/plotting-data-from-xml-that-has-timestamps-on-the-x-axis
Dirk Eddelbuettel
Thanks for the input. I have been playing around with the strptime function and it is very useful if I want to get the mean times. However, for the moment this functionality is not required. The suggested solution proposed by JoFrhwld has produced the required plot. I have a lot to learn about R as I do find some of the syntax of the commands strange. However, Thank you very much for your suggestions as it is nice to play around with these functions that will be useful in future.
Anthony Keane
Unless you explicitly convert your data to the correct time representation you will create **seriously misleading** plots!
hadley