How do I plot time (HH:MM:SS) in X axis in R -


i have tried read through stackoverflow, blogs, books etc have been unable find answer on plotting time in x-axis in following format(hh:mm:ss.000) in r , quantity on y-axis. have following dataset:

time             ecno 12:54:09.000    -14.47 12:54:10.000    -17.96 12:54:11.000    -15.97 12:54:12.000    -14.61 12:54:13.000    -12.68 12:54:14.000    -10.73 12:54:15.000    -10.54 12:54:16.000    -11.62 12:54:17.000    -12.49 12:54:18.000    -11.12 

how plot ecno on yaxis vs time(x axis) in format hh:mm:ss.000 shown above.

i appreciate help. many thanks

you may try ggplot:

library(ggplot2) df$time <- as.posixct(strptime(df$time, format="%h:%m:%s"))  # automatic scale selection ggplot(data = df, aes(x = time, y = ecno)) + geom_point() 

scale_x_datetime ggplot function, nice arguments date_breaks, , date_format need package scales:

library(scales)  ggplot(data = df, aes(x = time, y = ecno)) + geom_point() +   scale_x_datetime(breaks = date_breaks("1 sec"), labels = date_format("%s"))  ggplot(data = df, aes(x = time, y = ecno)) + geom_point() +   scale_x_datetime(breaks = date_breaks("1 sec"), labels = date_format("%os3"))  ggplot(data = df, aes(x = time, y = ecno)) + geom_point() +   scale_x_datetime(breaks = date_breaks("4 sec"), labels = date_format("%m:%s")) 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -