[英]How to make boxplot with a data frame with POSIXct format
我有一個帶有POSIXct格式的數據框。 我需要對我擁有的四列進行箱線圖繪制,但無法正常工作。
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 )
用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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.