0

This is a part of my dataset: Timestamps of this dataset

This is my code:

par(mfrow=c(2,5),cex=0.5)
for (m in 3:12){
  plot(TPP13_output[,1][1:loops2],TPP13_output[,m][1:loops2],col=2,
       xlab=colnames(TPP13_output[1]),ylab=colnames(TPP13_output[m]))
}

And these are plots of this code: plots

As you can see, the scales on x_axis are very sparse and show little details of these timestamps. I want to make x_axis be more denser and shows details like '2020-11-19 17:00:00'. I know that 'at' argument of 'axis' function can help to achieve this, but 'Timestamp1' is a 'POSIXct' type, I do not know how to correctly set this argument to let it accept this type.

1
  • It is easier to provide a solution if you made a MWE. Using dput(TPP13_output) would help people see the data you are using.
    – Calvin
    May 18, 2021 at 17:24

1 Answer 1

0

It is difficult to provide a full answer without a reproducible example. However, here is some sample code for adding time axes with different resolutions. Basically, I don't plot the axis on the initial figure (...axs='n') and add it separately with specific time resolution specified using the seq() function with the minimum time, maximum time, and time step (by argument in seconds) specified.

Different Time Resolution x Axis

# generate some random x and y values
x = as.POSIXlt("2017-02-03 08:00:00") + 100*rnorm(50, 0, 60*60)
y = cos(as.numeric(x)/(3600*25))+rnorm(length(x),0,0.3)

# making plots with different time steps
par(mfrow=c(3,1))
plot(x,y,
     xaxt='n',
     main='2 Days Ticks')
axis(side=1,
     at=seq(as.POSIXlt("2017-01-27 00:00:00"),as.POSIXlt("2017-02-9 23:59:59"),by=48*3600),
     labels = seq(as.POSIXlt("2017-01-27 00:00:00"),as.POSIXlt("2017-02-9 23:59:59"),by=48*3600)
     )

plot(x,y,
     xaxt='n',
     main='1 Day Ticks')
axis(side=1,
     at=seq(as.POSIXlt("2017-01-27 00:00:00"),as.POSIXlt("2017-02-9 23:59:59"),by=24*3600),
     labels = seq(as.POSIXlt("2017-01-27 00:00:00"),as.POSIXlt("2017-02-9 23:59:59"),by=24*3600)
)

plot(x,y,
     xaxt='n',
     main='12-Hour Ticks')
axis(side=1,
     at=seq(as.POSIXlt("2017-01-27 00:00:00"),as.POSIXlt("2017-02-9 23:59:59"),by=12*3600),
     labels = seq(as.POSIXlt("2017-01-27 00:00:00"),as.POSIXlt("2017-02-9 23:59:59"),by=12*3600)
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.