0

I have data in 3 columns:(as shown below

  • Date Time LTP
  • 20180102 09:16 1800
  • ... ... ... I wanna plot it in R so that I get time on the x-axis and LTP on the y-axis. Since there are around 360 rows every day (every minute LTP changes), the x variable shall be date:time I am new to R and I need help in this. Thanks in anticipation
krishna
  • 3
  • 1

1 Answers1

0

Try this:

library(zoo)
z <- read.zoo("myfile.dat", header = TRUE, index = 1:2, format = "%Y%m%d %H:%M", tz = "")

# classic graphics
plot(z)

# ggplot2 graphics
autoplot(z)

Note

To generate a file for the sample data provided in the question try this; however, with only one point you won't see anything on a line graph.

cat("Date Time LTP\n20180102 09:16 1800", file = "myfile.dat")
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341
  • Thank you so much for your reply .. Yes it did help me ..however, since my data is stock data, i have no data points from (example) 20180101 15:30 to 20180102 09:08 .. and same every day ..so in such case it is simple interpolating between the two points. Is there a way to make the program understand that there are no data points there and it shall treat 20180102 09:08 as the next point on x-axis after 20180101 15:30 .. I am trying to figure out from google, but any help here would be greatly appreciated. thank you again. – krishna Nov 12 '18 at 07:11
  • If you insert an NA between the valid points that will cause the line to be disconnected. Another approach to indicate this is to use `plot(z, xaxt = "n")` will omit X axis. Now use `axis.break` in the plotrix package. – G. Grothendieck Nov 12 '18 at 12:29
  • And a third approach is `plot(z, xaxt = "n", type = "n")` . Now use `lines` twice to overlay on that empty chart each subset separately. – G. Grothendieck Nov 12 '18 at 12:47