在 Lattice 中,scales
参数控制轴;可能与此未经测试的代码类似:
..., scales=list(y=list(at=seq.POSIXt(0, 700, length= 6),
labels=format(seq.POSIXt(0, 700, length= 6), "%H:%M:%S:)
), ...
为了得到这个经过测试的形式,我需要将秒转换为 POSIXt 格式:
mydata$val1time <- as.POSIXct(mydata$val1, origin="1970-01-01")
barchart(val1time ~ val2, groups=group, mydata, horizontal=FALSE,
scales=list( y=list(
at=seq.POSIXt(from=as.POSIXct(0, origin="1970-01-01"),
to=as.POSIXct(700, origin="1970-01-01"), length= 12),
labels=format( seq.POSIXt(from=as.POSIXct(0, origin="1970-01-01"),
to=as.POSIXct(720, origin="1970-01-01"), length= 12), "%H:%M:%S")
) ),
auto.key=list(
columns=1,
space="right",
text=c("Pilot 1","Pilot 2")
),
main="Title", xlab="Tasks", ylab="Duration"
)
如果你需要它从 0 向上,你需要添加:
..., ylim=range( as.numeric( seq.POSIXt(from=as.POSIXct(0, origin="1970-01-01"),
to=as.POSIXct(700, origin="1970-01-01"),
length= 12))) ,
为了显示一整套命令给出了该结果(添加了 'ylim' 参数,我粘贴了我使用数据框名称的代码dat
:
dat <- read.table(text="group,val2,val1
pilot01,t1,429.226015
pilot01,t3,693.795607
pilot02,t1,262.798468
pilot02,t3,325.854107", header=TRUE, sep=",")
dat$val1time <- as.POSIXct(dat$val1, origin="1970-01-01")
barchart(val1time ~ val2, groups=group, dat, horizontal=FALSE,
scales=list( y=list( at=seq.POSIXt(from=as.POSIXct(0, origin="1970-01-01"), to=as.POSIXct(700, origin="1970-01-01"), length= 12),
labels=format( seq.POSIXt(from=as.POSIXct(0, origin="1970-01-01"), to=as.POSIXct(720, origin="1970-01-01"), length= 12), "%H:%M:%S")
) ),
auto.key=list(
columns=1,
space="right",
text=c("Pilot 1","Pilot 2")
),
main="Title", xlab="Tasks", ylab="Duration"
, ylim=range( as.numeric( seq.POSIXt(from=as.POSIXct(0, origin="1970-01-01"),
to=as.POSIXct(700, origin="1970-01-01"),
length= 12))))