Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6562649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:44:02+00:00 2026-05-25T13:44:02+00:00

The other day I asked a question about how to get a histogram of

  • 0

The other day I asked a question about how to get a histogram of the date differences. I would like to do the same thing, but for groups and with a box plot, using lattice’s bwplot. Essentially, want 1 image with 5 box plots for each of the 5 different sources I have (I’ve shown 2 below in the example) — something like this image.

I’ve spent quite some time trying to figure this out, but cannot get it.

The closest I could come up

df <- read.csv("~/dates.csv", header = TRUE, sep = ",", quote = "\"")
a <- aggregate(as.POSIXct(as.character(df$REQUEST_DATE), format="%m/%d/%Y %H:%M:%S"), list(SOURCE=df$SOURCE), diff) # not sure if this is right (and I need -diff, but can't do that)
# now what?  I seem to know how to access a$SOURCE, but don't know how to look at the data associated with a$SOURCE.

The data (~/dates.csv):

"SOURCE","REQUEST_DATE"
"A","09/11/2011 09:28:48"
"A","09/11/2011 09:21:15"
"A","09/11/2011 09:15:42"
"A","09/11/2011 09:12:18"
"D","09/13/2011 09:06:53"
"D","09/13/2011 09:06:18"
"D","09/13/2011 08:56:55"
"D","09/13/2011 08:56:18"
"D","09/13/2011 08:55:43"
"D","09/13/2011 08:39:07"
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:44:03+00:00Added an answer on May 25, 2026 at 1:44 pm

    Here is a solution using the plyr package for the data analysis, and ggplot2 package for the plot:

    Read the data. Note the use of stringsAsFactors=FALSE – this saves lots of hassle converting to as.character later:

    df <- read.csv(textConnection('
    "SOURCE","REQUEST_DATE"
    "A","09/11/2011 09:28:48"
    "A","09/11/2011 09:21:15"
    "A","09/11/2011 09:15:42"
    "A","09/11/2011 09:12:18"
    "D","09/13/2011 09:06:53"
    "D","09/13/2011 09:06:18"
    "D","09/13/2011 08:56:55"
    "D","09/13/2011 08:56:18"
    "D","09/13/2011 08:55:43"
    "D","09/13/2011 08:39:07"
    '), stringsAsFactors=FALSE)
    

    Convert to POSIX date format:

    df$REQUEST_DATE <- as.POSIXct(df$REQUEST_DATE, format="%m/%d/%Y %H:%M:%S")
    

    Load plyr and use ddply to a) group by SOURCE, b) calculate difftime, c) group results into a data.frame, all in one step:

    library(plyr)
    df_diff <- ddply(df, .(SOURCE), summarize, TIME_DIFF=-unclass(diff(REQUEST_DATE)))
    df_diff
      SOURCE TIME_DIFF
    1      A      7.55
    2      A      5.55
    3      A      3.40
    4      D     35.00
    5      D    563.00
    6      D     37.00
    7      D     35.00
    8      D    996.00
    

    Load ggplot2 and plot. The plot looks a bit rubbish – that’s because the sample dataset is tiny. It will work better with larger datasets, i.e. you will get clear separation between median, range and outliers.

    library(ggplot2)
    ggplot(df_diff, aes(y=TIME_DIFF, x=SOURCE)) + geom_boxplot()
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Someone asked me a question via e-mail about integer partitions the other day (as
So the other day, I asked a question on Stackoverflow and got answers. But
This is very similar to a question I asked the other day but my
This is very similar to a question I asked the other day but my
So the other day, I asked this question about how to combine three complex
I asked a question the other day about how rows are added to a
I got this question in an interview the other day and would like to
I asked this question the other day and wasn't able to get the solution
I asked a dumb question the other day ( dumb question ) about the
I asked a similar question the other day but wasn't satisfied with the response,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.