简体   繁体   中英

How to plot Time Interval only on x axis without date?

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

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM