-3

I have a data frame with hourly data and I am trying to plot but I want date on x axis not just index as numbers, I want the dates to be shown on x axis

df = read.csv('~/Desktop/data.csv', header = TRUE , stringsAsFactors = FALSE)
df$Date <- as.POSIXct(strptime(df$Date,format= "%Y-%m-%d %H:%M:%OS"))
plot(df$column1)

index date

camille
  • 16,432
  • 18
  • 38
  • 60
Feddah
  • 3
  • 2
  • Can you please provide a reproducible example using for example `dput(yourDataframe[1:5,])`? – Georgery Feb 14 '20 at 14:50
  • [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R question that folks can help with, including a sample of data – camille Feb 14 '20 at 15:57

1 Answers1

0

The problem with your code seems to be that you feed a single variable into the plot command whereas what you want is a plot of column1 grouped by dates, right? If that's the case then you could use this:

DATA:

set-seed(123)
df <- data.frame(
  dates = rep(c("2009-01-01", "2009-01-02", "2009-01-03", "2009-01-04", "2009-01-05", "2009-01-06", "2009-01-07"), 1000),
  column1 = rnorm(7000, 100)
)

SOLUTION:

Then you could use ggplot2and geom_jitterto plot column1 against dates:

library(ggplot2)
ggplot(data=df, aes(x=dates, y=column1)) + geom_jitter() 

RESULT:

The resulting plot would roughly look like this: enter image description here

Chris Ruehlemann
  • 20,321
  • 4
  • 12
  • 34