0

I would like to create a histogram in R looking like this: Histogram count of 15 minutes interval of start and stopdates of weekend and weekdays

So a horizontal histogram that counts 15minutes (instead of the 20minutes in the picture) the start and stopdate of both the weekday and the weekend days.

I have been using the tips of Split time series data into time intervals (say an hour) and then plot the count, but I don't archieve to create the plot that I would like to have.

The dataset I have looks like this

DF < -Start_datetime End_datetime 2012-02-01 17:35:00 2012-02-01 17:43:44 2012-02-01 17:46:44 2012-03-01 17:50:44 2012-02-01 17:49:50 2012-02-01 18:49:54
2012-02-01 17:42:44 2012-03-01 08:10:44

This is what I tried (just to get the counting of the 15minutes interval done for the startdates):

PTU <- table (cut(DF$Start_datetime, breaks="15 minutes"))
data.frame(PTU)
ggplot(DF, aes(x=PTU))+
        geom_histogram(sta="count", color="blue") +
        labs(x = "Duration", y="Frequency")+
        ggtitle("Duration of charging session")+
        theme(plot.title = element_text(family="Roboto Light", size=16))+
        theme(axis.title = element_text(family="Roboto Light", size=14))

This is the message that I receive:

Warning: Ignoring unknown parameters: binwidth, bins, pad
Error in eval(expr, envir, enclos) : object 'PTU' not found
In addition: There were 14 warnings (use warnings() to see them)

Is there anyone that can help me out to adjust the graph to a seperated one for weekdays/weekends and to properly count the intervals from the dates? Thanks a lot!

ima
  • 155
  • 12
  • can you show us `dput(DF)` ? The last part of your date is not seconds so I don't understand the format – moodymudskipper Jun 09 '17 at 14:33
  • Something went wrong with copying the data to the question, so sorry. I have edited the question:). Thank you for your comment! – ima Jun 12 '17 at 07:24
  • it would still be easier if you gave a dput of your data, dput(DF) or head(dput(DF),20), and give the packages that you're using, because with what you have I get an error already at `PTU <- table (cut(DF$Start_datetime, breaks="15 minutes"))` . help on cut says "either a numeric vector of two or more unique cut points or a single number (greater than or equal to 2) giving the number of intervals into which x is to be cut." for me, so I'm not sure how you're passing this string argument. – moodymudskipper Jun 13 '17 at 13:49

0 Answers0