如何使用POSIXct格式的数据框制作boxplot

问题描述:

我有POSIXct fomat的数据框。我需要制作我拥有的四个柱子的盒子图,但它不起作用。如何使用POSIXct格式的数据框制作boxplot

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

https://*.com/questions/11346880/r-plot-multiple-box-plots-using-columns-from-data-框架 –

+0

@ s.brunel我知道如何用ggplot制作boxplot,但是我的问题与我的数据框的格式有关。 – Mori

+0

也许这只是你的代码:DF $ Site.1350

是没有问题的,以与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)