Reputation: 109
I am using R-3.2.4. I have been trying to plot the data with only time on x axis and some value on y axis but everytime it shows some date on along with time on x axis, however i need only time interval on x axis.
Here is the code that i am using:
data_plot<- read.csv("C:/.../Data_pract.csv",header=TRUE,stringsAsFactors=F)
data_plot$Time<-as.POSIXct(strptime(data_plot$Time, format="%H:%M"))
mydata<-ggplot(data_plot,aes(x=Time,y=January))+geom_line()
mydata
Here is the sample data that i am using:
Time January
0:00 20
0:15 30
0:30 45
0:45 40
1:00 28
1:15 15
I have attached image of graph that i am looking for.
Thanks in advance.enter image description here
Upvotes: 0
Views: 3076
Reputation: 61
You can change the scale in ggplot to datetime by using the function scale_x_datetime
mydata<-ggplot(data_plot,aes(x=Time,y=January)) + geom_line() +
scale_x_datetime(date_breaks = "1 hour",
date_labels = "%I:%M %p")
Upvotes: 2