[R] date and time data on x axis

snowball0916 @nowb@||0916 @end|ng |rom 163@com
Tue Oct 30 19:25:00 CET 2018


Hi, Rui
Thank you . I will try later.
Thanks again.

 
 


 
From: Rui Barradas
Date: 2018-10-30 00:38
To: snowball0916; r-help
Subject: Re: [R] date and time data on x axis
Hello,
 
Inline.
 
Às 14:03 de 29/10/2018, snowball0916 escreveu:
> Hi, Rui
> Thanks for your code, even though I'm not fully understand it.
> And I am new to R, could you kindly help me with
> -1). what's the nested usage stand for?
> op <- par(mar = c(4, 0, 0, 0) + par("mar"))
 
See the help for ?par. You have
 
mar
A numerical vector of the form c(bottom, left, top, right) which gives 
the number of lines of margin to be specified on the four sides of the 
plot. The default is c(5, 4, 4, 2) + 0.1.
 
 
So par("mar") returns c(5.1, 4.1, 4.1, 2.1)
In order to see the x axis labels, that are longer than normal, I have 
added 4 to the bottom only, c(4, 0, 0, 0) + default_value.
And par() returns the previous values of the graphices parameters, so 
save them in op (old param) and restore the defaults when done plotting.
 
> 
> -2). how can I get the axis.POSIXct usage or help?
> I use help(axis)and help(POSIXct)and not found the actual use.
 
It's ?axis.POSIXct or help('axis.POSIXct'). You want the S3 method for 
objects of class "POSIXct".
 
Hope this helps,
 
Rui Barradas
 
> 
> Thanks very much.
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
>     *From:* Rui Barradas <mailto:ruipbarradas using sapo.pt>
>     *Date:* 2018-10-29 02:53
>     *To:* snowball0916 <mailto:snowball0916 using 163.com>; r-help
>     <mailto:r-help using r-project.org>
>     *Subject:* Re: [R] date and time data on x axis
>     Hello,
>     Maybe you could get some inspiration in the following code.
>     op <- par(mar = c(4, 0, 0, 0) + par("mar"))
>     plot(xdata, ydata, type = "o", xaxt = "n")
>     axis.POSIXct(1, xdata, at = xdata, labels = xdata, las = 2)
>     par(op)
>     The important part is the call axis.POSIXct, argument las = 2 and the
>     call to par is to make sure that the labels are visible.
>     Hope this helps,
>     Rui Barradas
>     Às 15:16 de 28/10/2018, snowball0916 escreveu:
>      > 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