我有一个带有POSIXct fomat的数据框。我需要制作我所拥有的四列的箱形图,但它不起作用。
Site.1350 Site.1700 Site.2000 Site.2300
15:15:08 15:29:08 15:32:50 15:34:12
15:02:32 15:23:43 15:21:06 15:34:50
14:40:34 14:58:30 15:21:06 15:32:50
15:15:08 15:29:08 15:21:06 15:34:50
15:10:03 14:58:30 15:30:01 15:34:12
15:23:43 15:19:42 15:30:01 15:34:00
14:56:24 15:29:08 15:21:06 15:34:50
15:15:08 14:58:30 15:24:56 15:34:50
15:15:08 14:58:30 15:32:50 15:34:12
14:56:24 14:42:57 15:32:50 15:34:50
14:56:24 14:47:35 15:21:06 15:30:01
14:56:24 15:23:43 15:24:56 15:34:12
15:15:08 14:49:51 15:30:01 15:34:12
15:02:32 15:32:50 15:30:01 15:27:10
15:10:03 15:29:08 15:34:12 15:34:12
这是我使用的代码:
DF <- read.csv2(file="Photoperiod.csv")
DF$Site.1350 <-as.POSIXct(DF$Site.1350 , format = "%H:%M:%S")
DF$Site.1700 <-as.POSIXct(DF$Site.1700 , format = "%H:%M:%S")
DF$Site.2000 <-as.POSIXct(DF$Site.2000 , format = "%H:%M:%S")
DF$Site.2300 <-as.POSIXct(DF$Site.2300 , format = "%H:%M:%S")
boxplot(DF )
答案 0 :(得分:0)
制作带有POSIXct数据的箱线图没有问题。关键是轴看起来不太好,因为R不打印人类可读的标签。一个解决方案是通过自己控制轴标签:
# create data
random <- round(runif(10,0,59))
p_time <- as.POSIXct( strptime( paste0("2011-03-27 01:", random ,":00"), "%Y-%m-%d %H:%M:%S" ))
random <- round(runif(10,0,59))
p_time2 <- as.POSIXct( strptime( paste0("2011-03-27 02:", random ,":00"), "%Y-%m-%d %H:%M:%S" ))
# make boxplot
boxplot(p_time, p_time2, axes=F)
box()
# make axis
dd <- c(p_time, p_time2)
ff <- seq(min(dd), max(dd), length.out = 5)
axis(2, at=seq(min(dd), max(dd), length.out = 5), labels = F )
text(x=0.3, y=ff, labels=format(ff, format = "%H:%M"), xpd=NA, pos=2)