-2

I am having a csv file which contains 2 column date(format yyyymmdd) and value on that date. File contains only 12 values and when I am plotting them on scatterplot using R only few of them are displayed on the axis rest are not displayed.

Similar questions I had seen and they all are suggesting to use axis() for this but this is not working for me. Is there any other method to do it? I need all the date values to be shown on x axis and dates which are displayed on x-axis are not present in my data. Maybe R is treating date as Integer.

Sample data:

20170801,1.234
20171010,1.22
zx8754
  • 52,746
  • 12
  • 114
  • 209
  • 1
    Possible duplicate https://stackoverflow.com/questions/5182238/replace-x-axis-with-own-values – zx8754 Jan 08 '18 at 09:52

1 Answers1

0

Use axis.Date():

d <- data.frame(Date=c("20170801","20171010"),
                value=c(1.234,1.22))

plot(as.Date(d$Date, "%Y%m%d"), 
     d$value, 
     type="l", 
     xaxt = "n",
     xlab = "Date",
     ylab = "Value"
     )

axis.Date(1, at = as.Date(d$Date, "%Y%m%d"), "%Y%m%d")

enter image description here

Martin C. Arnold
  • 9,483
  • 1
  • 14
  • 22