Error: Invalid input: time_trans works with objects of class POSIXct only

library(reshape)
library(dplyr)
library(ggplot2)
library(plotrix)

tide.dec$Time<-paste(tide.dec$DAY, tide.dec$HOUR, sep=" ")

tide.dec<-na.omit(tide.dec)

tide.dec$Time<-as.POSIXct(tide.dec$Time,format="%d-%m-%Y %H:%M",tz="UTC")
tide.dec$days<-as.numeric(substring(tide.dec$DAY,1,2))
str(tide.dec)

#####3.1. Tide plot for december ####

ggplot(data=subset(tide.dec,tide.dec$days>22&tide.dec$days<31),aes(x=HOUR,y=HEIGHT))+
geom_line(col="blue",size=1)+
labs(x="Time",y="Tidal height(m)",title="Tidal changes in Dec-2022. Red blocks indicate observing time at VP")+
theme_bw()+
theme(axis.text.x = element_text(size=8),
axis.text.y = element_text(size=10))+
scale_x_datetime(date_breaks = "04 hours", date_labels = "%Y-%m-%d %H:%M:%S")+
theme(axis.text.x = element_text(angle = 90, hjust = 1))+
#Day1
annotate("rect",
xmin = as.POSIXct("2022-12-23 06:30:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
xmax = as.POSIXct("2022-12-23 16:30:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
ymin = -Inf, ymax = Inf, fill = "red", alpha=.3)+
#Day2
annotate("rect",
xmin = as.POSIXct("2022-12-24 06:30:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
xmax = as.POSIXct("2022-12-24 16:30:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
ymin = -Inf, ymax = Inf, fill = "red", alpha=.3)+
#Day3
annotate("rect",
xmin = as.POSIXct("2022-12-25 07:30:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
xmax = as.POSIXct("2022-12-25 17:30:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
ymin = -Inf, ymax = Inf, fill = "red", alpha=.3)+
#Day4
annotate("rect",
xmin = as.POSIXct("2022-12-26 07:30:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
xmax = as.POSIXct("2022-12-26 18:00:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
ymin = -Inf, ymax = Inf, fill = "red", alpha=.3)+
#Day5
annotate("rect",
xmin = as.POSIXct("2022-12-27 08:00:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
xmax = as.POSIXct("2022-12-27 18:30:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
ymin = -Inf, ymax = Inf, fill = "red", alpha=.3)+
#Day6
annotate("rect",
xmin = as.POSIXct("2022-12-28 05:30:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
xmax = as.POSIXct("2022-12-28 16:00:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
ymin = -Inf, ymax = Inf, fill = "red", alpha=.3)+
#Day7
annotate("rect",
xmin = as.POSIXct("2022-12-29 05:30:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
xmax = as.POSIXct("2022-12-29 16:00:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
ymin = -Inf, ymax = Inf, fill = "red", alpha=.3)+
#Day8
annotate("rect",
xmin = as.POSIXct("2022-12-30 06:30:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
xmax = as.POSIXct("2022-12-30 16:30:00",format="%Y-%m-%d %H:%M:%S",tz="UTC"),
ymin = -Inf, ymax = Inf, fill = "red", alpha=.3)

Hi xuanhien , welcome to the forum

I do not think we can help without some sample data.
A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need. Just do dput(mydata) where mydata is your data. Copy the output and paste it here.

For some general information see FAQ

oh, thank you so much, I solved my problem.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.