-1

I am having a problem plotting a line using qplot. I've reviewed previous posts related to ggplot2 (e.g. ggplot2 each group consists of only one observation), but my problem is a bit different.

I only want a simple line graph plotting temperature against time (ymd_hms). Not two lines.

My data looks like this:

Date.time

2011/06/17 00:00:00

2011/06/17 00:30:00

2011/06/17 01:00:00

2011/06/17 01:30:00

2011/06/17 02:00:00

2011/06/17 02:30:00

2011/06/17 03:00:00

2011/06/17 03:30:00




Temp

71.1

71.1

71.1

71.1

70.8

70.8

70.8

70.5

This is the code I've used:

as.POSIXct(data$Date.time, format = "%Y/%m/%d %H:%M:%S") 
qplot(Date.time, Temp, data=mydata, geom="line")
But I get this error:
"Each group consists of only one observation.  Do you need to adjust the group aesthetic?"

How can I fix this?

Thank you!

Community
  • 1
  • 1

1 Answers1

2

I think in your problem, you should change data=mydata to data=data, then it should work.

Here is a solution:

data <- structure(list(date.time = structure(c(1308288600, 1308290400, 
1308292200, 1308294000, 1308295800, 1308297600, 1308299400), class = c("POSIXct", 
"POSIXt"), tzone = ""), temperature = c(71.1, 71.1, 71.1, 70.8, 
70.8, 70.8, 70.5)), .Names = c("date.time", "temperature"), row.names = c(NA, 
-7L), class = "data.frame")

data$date.time <- as.POSIXct(data$date.time,format="%m/%d/%Y %H:%M")

library(ggplot2)
qplot(data=data,x=date.time,y=temperature,geom="line")

The output is as follows:

enter image description here

Jd Baba
  • 5,948
  • 18
  • 62
  • 96
  • It looks like my problem was that I had this:as.POSIXct(data$Date.time, format = "%Y/%m/%d %H:%M:%S" instead of data$Date.time<-as.POSIXct(data$Date.time, format = "%Y/%m/%d %H:%M:%S"). Thank you for the code. – user2263130 Jul 14 '13 at 20:34