This is in R ver3.4.2 programming.I am about to plot a certain variable of a dataframe, say Y, against the weekdays of the Dates. I have been through some references but none so far worked. I have tried the following: (the dataframe has Date, Time and Y)
library(dplyr)
library(lubridate)
library(datasets)
df$Date<- as.Date(df$Date, "%d/%m/%Y")
df$Time<- strptime(df$Time, "%H:%M:%S")
df$Time<- as.POSIXct(df$Time)
#select data for certain dates
selected_data<-with(df, df[(Date >= "2017-01-12" & Date <= "2017-01-13"),])
Y<- as.numeric(as.character(selected_data$Y))
#these are my trials in trying to plot the weekdays
#trial 1
wkdays <- weekdays(selected_data$Date)
#trial 2
dat <- format(selected_data$Date,"%Y-%m-%d")
pl<-plot(dat,Y, type="l" , ylab = "Y", xlab=" ")
#pl<-plot(wkdays, Y, type="l" ,xaxt="n", ylab = "Y", xlab=" ")
#pl<- plot(Y, type="l", ylab = "Y", xlab=" ")
axis(1,at=as.Date.numeric(selected_data$Date), labels=format(weekday))
#axis.Date(1, at=seq(weekday), "days",labels = TRUE)
#axis.Date(1, at=seq(min(wkdays),max(wkdays), by = "%d"), "days",labels = TRUE,tcl = -0.2)
axis(2, at= seq(0, max(Y), by = 2))
The output should be a line plot of Y data vs Index with ticks labeled with the weekdays of the Dates (Mon, Tue, etc) with a certain tick intervals.
If anyone has a link with the answer (maybe I have diff keywords), please help and share it below. Thank you!
Here's a sample dataset:
Date;Time;Y;
2017-01-12;2018-02-27 00:00:00;"0.715";
2017-01-12;2018-02-27 00:01:00;"0.438";
2017-01-12;2018-02-27 00:02:00;"0.734";
2017-01-12;2018-02-27 00:03:00;"0.646";
2017-01-12;2018-02-27 13:19:00;"1.268";
2017-01-13;2018-02-27 13:20:00;"0.108";
2017-01-13;2018-02-27 13:21:00;"0.961";
2017-01-13;2018-02-27 13:22:00;"0.570";
2017-01-13;2018-02-27 13:23:00;"0.192";
2017-01-13;2018-02-27 13:24:00;"1.280";