0

This is my data frame, from this data frame i plot time series graph

data.frame(df3)

Time                 Price
2/21/2018 09:00:00am 122.12
2/21/2018 09:07:38am 122.43
2/21/2018 09:09:10am 122.44
2/21/2018 09:09:10am 122.45
2/21/2018 09:09:21am 122.26
2/21/2018 09:13:16am 122.37

...

this is coding for time series graph:

ts.plot(df3$Price, gpars=list(xlab="Time", ylab="Price"))

the output is:

enter image description here

i want to change x-label on my graph, i want the format of my x-label display "2/21/2018 09:13:16am " format

Thanks in advance

arvi1000
  • 9,393
  • 2
  • 42
  • 52
  • 1
    You may want to post the value of `class(df3$Time)`. Also see this question: https://stackoverflow.com/questions/20602801/set-x-axis-labels-to-dates-when-plotting-time-series – arvi1000 Jul 21 '18 at 03:50

1 Answers1

1

"i want the format of my x-label display "2/21/2018 09:13:16am" format" I'm not sure what you mean. I assume you want ticks and labels for sensible time points of your time series data.

I would recommend using zoo.

# Load sample data
df <- read.table(text =
    "Time                 Price
    '2/21/2018 09:00:00am' 122.12
    '2/21/2018 09:07:38am' 122.43
    '2/21/2018 09:09:10am' 122.44
    '2/21/2018 09:09:10am' 122.45
    '2/21/2018 09:09:21am' 122.26
    '2/21/2018 09:13:16am' 122.37", header = T)

# Convert data.frame to zoo time series object
library(zoo)
Price <- zoo(df$Price, as.POSIXct(df$Time, format = "%m/%d/%Y %I:%M:%S%p"))

# Plot
library(ggplot2)
autoplot(Price) + labs(x = "Time")

enter image description here

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68