[R] Datetime misrepresented on x-axis of a multiple plot

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Sat May 2 00:46:50 CEST 2020


Hi Ogbos,
The following code may get you close to what you want. I have used the
names of the columns in "dta" as it is less confusing for me. I think
you meant to request horizontal ablines as none appeared in the
example. In order to get the axis tick label "Sun" you would have to
increase the x axis limits beyond your data.

plot(dta$datetime,dta$B,type="l",axes=FALSE)
# this is out of range and doesn't appear
abline(h=-3,col="red")
axis(2)
plot(dta$datetime,dta$LAT,type="l",axes=FALSE)
abline(h=-3,col="red")
axis(2)
plot(dta$datetime,dta$BX,type="l",axes=FALSE)
abline(h=-3,col="red")
axis(2)
axis.POSIXct(1,dta$datetime,format="%a")
mtext("A1", side = 1, outer = TRUE, line = 2.2)
mtext("B1", side = 2, outer = TRUE, line = 2.2,at =0.2)
mtext("B2", side = 2, outer = TRUE, line = 2.2,at =0.5)
mtext("B2", side = 2, outer = TRUE, line = 2.2,at =0.8)

Jim

On Sat, May 2, 2020 at 2:47 AM Ogbos Okike <giftedlife2014 using gmail.com> wrote:
>
> Dear Contributors,
> I am trying to do a plot with multiple y-axis on a common x-axis. I have
> made some progress but I am having difficulties with datetime appearing on
> x-axis. Instead of as date, it appears as large numbers.
> ...
> If I do a simple plot of x and B, the x-axis will be fine, appearing as
> Thu, Fri, Sat, Sun.
> Please let me know what I am doing wrong with the multiple plot code above.
> I want the same Thu, Fri, Sat, Sun to appear on the common x-axis.
>



More information about the R-help mailing list