Problems making a graph using datatime x-axis in R

Viewed 30

I have a huge database where I extracted only three days to explore the temperature along each hour per day. Data looks like this:

head(agosto123)

     X       date     Hour   temp     HR place placeconse            datetime
1 2266 0001-08-15 00:00:00 27.801 82.797 fundo       8905 0001-08-15 00:00:00
2 2269 0001-08-15 01:00:00 27.949 83.745 fundo       8906 0001-08-15 01:00:00
3 2302 0001-08-15 02:00:00 28.196 84.343 fundo       8907 0001-08-15 02:00:00
4 2317 0001-08-15 03:00:00 28.345 84.375 fundo       8908 0001-08-15 03:00:00
5 2320 0001-08-15 04:00:00 28.444 84.740 fundo       8909 0001-08-15 04:00:00
6 2323 0001-08-15 05:00:00 28.518 84.699 fundo       8910 0001-08-15 05:00:00

....plus other 90 observations

I tried the next option:

agosto123$datetime<-as.POSIXct(agosto123$datetime, format="%d-%m-%Y %H:%M:%S")

tempagosto123<-ggplot(agosto123,
              aes(aes(datetime, temp)))+
geom_point(colour= "blue")+
geom_line(aes(colour = "red"))
temapgosto123

It appears the next error:

Don't know how to automatically pick scale for object of type uneval. Defaulting to continuous. Error: Aesthetics must be either length 1 or the same as the data (96): x

Then, I tried a second option:

tempagosto123<-ggplot(agosto123,
              aes(aes(datetime, temp)))+
geom_point(colour= "blue")+
geom_line(aes(colour = "red"))+
scale_x_datetime(breaks = date_breaks("60 min"))
tempagosto123

And it appears the next error: Error: Aesthetics must be either length 1 or the same as the data (96): x

Could you please, tell me what I am doing wrong? Thanks in advance for your help!

The graph that I get when I removed one aes in this code:

tempagosto123<-ggplot(agosto123(aes(datetime, temp))+ geom_point(colour= "blue")+ geom_line(aes(colour = "red"))+ scale_x_datetime(breaks = date_breaks("60 min")) tempagosto123

enter image description here

Data for each hour is stacked per day and that is wrong. Thanks for all your help!

0 Answers
Related