[R] date and time data on x axis

snowball0916 @nowb@||0916 @end|ng |rom 163@com
Mon Oct 29 15:10:53 CET 2018


Hi, Jim
Thanks very much, I will need to study your code, though.
Will large volume of data will affect the x axis display?
Thanks again. 
 


 
From: jim holtman
Date: 2018-10-29 05:53
To: snowball0916
CC: R mailing list
Subject: Re: [R] date and time data on x axis
You need to specify what the format of the date will be.  I am using
ggplot for the plot:
 
 
    library(lubridate)
    library(tidyverse)
    mydata <- read.table(text = "time value
    20181028_10:00:00 600
    20181028_10:00:01 500
    20181028_10:00:02 450
    20181028_10:00:03 660", header = TRUE, as.is = TRUE)
 
    mydata <- mutate(mydata,
                     time = ymd_hms(time)
    )
 
    ggplot(mydata, aes(time, value)) +
      geom_point() +
      scale_x_datetime(date_labels = "%m/%d %H:%M:%S"
      ) +
      theme(axis.text.x = element_text(angle = 25, vjust = 1.0, hjust = 1.0))
 
Jim Holtman
Data Munger Guru
 
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.
 
Jim Holtman
Data Munger Guru
 
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.
 
 
On Sun, Oct 28, 2018 at 11:23 AM snowball0916 <snowball0916 using 163.com> wrote:
>
> Hi, guys
> How do you guys deal with the date and time data on x axis?
> I have some trouble with it. Could you help with this?
>
> =============
> Sample Data
> =============
> The sample data look like this:
>
> 20181028_10:00:00 600
> 20181028_10:00:01 500
> 20181028_10:00:02 450
> 20181028_10:00:03 660
> ......
>
> =============
> My Code
> =============
>
> library(lubridate)
> mydata <- read.table("e:/R_study/graph_test2.txt")
> xdata <- ymd_hms(mydata$V1)
> ydata <- mydata$V2
> plot(xdata, ydata, type="o")
>
>
> =============
> Questions:
> =============
>
> 1. Why my x axis does not show me the correct date time like ""2018-10-28 10:00:00 UTC" ?
> 2. If my data is very huge(like data in every second and the data has the whole day , even the whole month), how can I display the x axis in a neat and clean way?
>
> Thanks very much.
>
>
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]



More information about the R-help mailing list