0

I have a data frame with the POSIXct fomat. i need to make boxplot of the four columns that i have, but it is not working.

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

here is the code i used:

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 )
Mori
  • 241
  • 1
  • 2
  • 10
  • https://stackoverflow.com/questions/11346880/r-plot-multiple-box-plots-using-columns-from-data-frame – s.brunel Aug 09 '17 at 13:38
  • @s.brunel i know how to make boxplot with ggplot but my problem is with the format of my data frame. – Mori Aug 09 '17 at 13:42
  • Maybe it´s just your code: DF$Site.1350 <-as.POSIXct(DF$Site.1350 , format = "%H:%M:%S") insted of DF$Site.1350 <-as.POSIXct(DFSite.1350 , format = "%H:%M:%S") ??? Is that what is holding you back? – Patrik_P Aug 09 '17 at 13:57
  • It edited the question – Mori Aug 09 '17 at 14:01

1 Answers1

0

There is no problem to make a boxplot with POSIXct data. The point is only the axis looks not so nice because R don't print human readable labels. One solution for this is to control the axis labels by your self:

# 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)
and-bri
  • 1,563
  • 2
  • 19
  • 34