The R Project SVN R

Rev

Rev 80947 | Rev 86239 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 80947 Rev 83601
Line 158... Line 158...
158
toD <- as.Date("2016-08-19"); dates <- c(toD - 10, toD)
158
toD <- as.Date("2016-08-19"); dates <- c(toD - 10, toD)
159
plot(dates, 1:2, xlim = rev(dates),
159
plot(dates, 1:2, xlim = rev(dates),
160
     ann=FALSE, yaxt="n", frame.plot=FALSE)
160
     ann=FALSE, yaxt="n", frame.plot=FALSE)
161
## failed to label the dates in R <= 3.3.1
161
## failed to label the dates in R <= 3.3.1
162
 
162
 
-
 
163
## axis.Date() with various data types:
-
 
164
x <- seq(as.Date("2022-01-20"), as.Date("2023-03-21"), by = "days")
-
 
165
plot(data.frame(x, y = 1), xaxt = "n")
-
 
166
axis.Date(1)
-
 
167
axis.Date(3, at = "2022-04-01")
-
 
168
axis.Date(3, at = as.Date("2022-07-01"))
-
 
169
axis.Date(3, at = as.POSIXct(as.Date("2022-10-01")))
-
 
170
axis.Date(3, at = as.POSIXlt(as.Date("2023-01-01")))
-
 
171
axis.Date(3, at = as.integer(as.Date("2023-04-01")))
-
 
172
## automatically extends the format:
-
 
173
axis.Date(1, at = "2022-02-15", tck = -0.05, mgp = c(3,2,0))
-
 
174
 
-
 
175
## axis.POSIXct() with various data types (2 minutes)
-
 
176
x <- as.POSIXct("2022-10-01") + c(0, 60, 120)
-
 
177
plot(data.frame(x, y = 1), xaxt="n")
-
 
178
axis.POSIXct(1)
-
 
179
axis.POSIXct(3, at = "2022-10-01 00:01")
-
 
180
axis.POSIXct(3, at = as.Date("2022-10-01"))
-
 
181
axis.POSIXct(3, at = as.POSIXct("2022-10-01 00:01:30"))
-
 
182
axis.POSIXct(3, at = as.POSIXlt("2022-10-01 00:02"))
-
 
183
axis.POSIXct(3, at = as.numeric(as.POSIXct("2022-10-01 00:00:30")))
-
 
184
## automatically extends format (here: subseconds):
-
 
185
axis.POSIXct(3, at = "2022-10-01 00:00:30.25", mgp = c(3,2,0))
-
 
186
 
-
 
187
## axis.POSIXct: a few days, extending the format
-
 
188
days <- seq(as.Date("2022-10-01"), as.Date("2022-12-21"), by="days")
-
 
189
x <- as.POSIXct(as.character(days))
-
 
190
plot(data.frame(x, y = 1), xaxt="n")
-
 
191
axis.POSIXct(1, x)
-
 
192
axis.POSIXct(1, x, at = as.Date("2022-10-12"), mgp = c(3,2,0), tck = -0.04)
-
 
193
axis.POSIXct(3, x, at = as.POSIXct("2022-10-15"))
-
 
194
axis.POSIXct(3, x, at = as.POSIXlt("2022-10-15"), mgp = c(3,2,0))
-
 
195
axis.POSIXct(1, x, at = "2022-11-01 23:00", mgp = c(3,2,0), tck = -0.04)
-
 
196
axis.POSIXct(3, x, at = "2022-11-01 06:00")
-
 
197
axis.POSIXct(3, x, at = as.numeric(as.POSIXct("2022-12-01")))
163
 
198
 
164
## axis() -- labels only written when there's room
199
## axis() -- labels only written when there's room
165
plot2 <- function(at, wait=FALSE) {
200
plot2 <- function(at, wait=FALSE) {
166
    plot1 <- function(x,y) plot(x,y, type="n", xlab="", ylab="", tck=0, frame.plot=FALSE)
201
    plot1 <- function(x,y) plot(x,y, type="n", xlab="", ylab="", tck=0, frame.plot=FALSE)
167
    plot1( at, at); axis(3, at= at, tck=0)
202
    plot1( at, at); axis(3, at= at, tck=0)